正则表达式:有没有办法设置模式的最大大小? [英] Regular expression: is there a way to set maximum size of pattern?

查看:36
本文介绍了正则表达式:有没有办法设置模式的最大大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我有字符串:
0123456789

For example, if I have the string:
0123456789

我会这样写表达式:
0.*9 WHERE PATTERN MAX SIZE 为 3.在这种情况下,模式应该失败.

推荐答案

x{min,max} 将匹配最小和最大次数之间的 x
x{min,} 将至少匹配 x 分钟
x{,max} 最多匹配 x 次
x{n} 将精确匹配 x n 次

x{min,max} will match x between min and max times
x{min,} will match x at least min times
x{,max} will match x at most max times
x{n} will match x exactly n times

所有范围都包含在内.

快捷方式:{0,1} => ?, {0,} => *,{1,} => +.

Shortcuts: {0,1} => ?, {0,} => *, {1,} => +.

我不确定这是否正是您所需要的,但它应该可以帮助您构建正则表达式.

I'm not sure if this is exactly what you need, but it should help you build your regex.

示例:^0\d{,3}9$ 将匹配最多 5 位以 0 开头并以 9 结尾的字符串.匹配:0339, <代码>06319,09.不匹配:0334291449.

Example: ^0\d{,3}9$ will match strings with at most 5 digits starting with 0 and ending with 9. Matches: 0339, 06319, 09. Does not match: 033429, 1449.

这篇关于正则表达式:有没有办法设置模式的最大大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆