正则表达式:有没有办法设置模式的最大大小?

问题描述:

例如,如果我有字符串:
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.