gpt4 book ai didi

regex - 如何匹配小于或等于100的数字?

转载 作者:行者123 更新时间:2023-12-03 10:09:32 26 4
gpt4 key购买 nike

我想匹配一个小于或等于100的数字,它可以是0到100之间的任何数字,但是正则表达式不应该匹配大于100的数字,例如120、130、150、999等。

最佳答案

试试这个

\b(0*(?:[1-9][0-9]?|100))\b

说明
"
\b # Assert position at a word boundary
( # Match the regular expression below and capture its match into backreference number 1
0 # Match the character “0” literally
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
(?: # Match the regular expression below
# Match either the regular expression below (attempting the next alternative only if this one fails)
[1-9] # Match a single character in the range between “1” and “9”
[0-9] # Match a single character in the range between “0” and “9”
? # Between zero and one times, as many times as possible, giving back as needed (greedy)
| # Or match regular expression number 2 below (the entire group fails if this one fails to match)
100 # Match the characters “100” literally
)
)
\b # Assert position at a word boundary
"

关于regex - 如何匹配小于或等于100的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11011674/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com