someone can help me how to implement the following pattern as a regular expression?
有人可以帮我如何实现以下模式作为正则表达式?
apple(x,y);
Where
0 <= x,y <= 100
其中0 <= x,y <= 100
So valid results would include the following:
所以有效的结果将包括以下内容:
apple(0,0);
apple(0,10);
apple(77,12);
apple(100,0);
apple(100,100);
I hope someone can help me. Thanks so much
我希望有一个人可以帮助我。非常感谢
2 个解决方案
#1
1
Using a number range tool I get something like this
使用数字范围工具,我得到这样的东西
apple\(0*(\d|[1-9]\d|100),0*(\d|[1-9]\d|100)\);
apple
\(
0*
( # (1 start)
\d
| [1-9] \d
| 100
) # (1 end)
,
0*
( # (2 start)
\d
| [1-9] \d
| 100
) # (2 end)
\);
#2
1
You can use a character class to specify the range of your number and the quantifier {}
to limit the repetition :
您可以使用字符类指定数字的范围,使用量词{}来限制重复:
apple\([0-9]+,(?:[0-9]{1,2}|100)\);
See demo https://regex101.com/r/eG8kE6/2
请参阅演示https://regex101.com/r/eG8kE6/2
Read more about regex http://www.regular-expressions.info/repeat.html
阅读更多关于正则表达式http://www.regular-expressions.info/repeat.html
#1
1
Using a number range tool I get something like this
使用数字范围工具,我得到这样的东西
apple\(0*(\d|[1-9]\d|100),0*(\d|[1-9]\d|100)\);
apple
\(
0*
( # (1 start)
\d
| [1-9] \d
| 100
) # (1 end)
,
0*
( # (2 start)
\d
| [1-9] \d
| 100
) # (2 end)
\);
#2
1
You can use a character class to specify the range of your number and the quantifier {}
to limit the repetition :
您可以使用字符类指定数字的范围,使用量词{}来限制重复:
apple\([0-9]+,(?:[0-9]{1,2}|100)\);
See demo https://regex101.com/r/eG8kE6/2
请参阅演示https://regex101.com/r/eG8kE6/2
Read more about regex http://www.regular-expressions.info/repeat.html
阅读更多关于正则表达式http://www.regular-expressions.info/repeat.html