Regex 正则表达式-匹配3位数字
我正在寻找代码编辑器(括号)的正则表达式,以查找以下格式的3位数字Regex 正则表达式-匹配3位数字,regex,Regex,我正在寻找代码编辑器(括号)的正则表达式,以查找以下格式的3位数字 129 (3-digit WITHOUT DOT) 107.23 (3-digit DOT 2-digit) 但不是 117.234 (3-digit DOT 3-digit or more) X306 (Character before number) 我试过:[0-9]{3,3}[.][0-9]{0,2}\b\d{3,3}\b 但它也部分匹配了117.234/105.123432 X306 50.17080 8.6950
129 (3-digit WITHOUT DOT)
107.23 (3-digit DOT 2-digit)
但不是
117.234 (3-digit DOT 3-digit or more)
X306 (Character before number)
我试过:[0-9]{3,3}[.][0-9]{0,2}\b\d{3,3}\b
但它也部分匹配了117.234/105.123432
X306
50.17080
8.69507,
50.178075,
50.050512
117.234
49.172
129
105.123432
107.23
你可以用
\b(?<!\d\.)\d{3}(?:\.\d{1,2})?\b(?!\.\d)
\b(?)?
看
详细信息
\b(?-前面没有数字和点的单词边界
\d{3}(?:\.\d{1,2})
-3位数字,后跟可选的
序列和1或2位数字
\b(?!\.\d)
-单词边界后面没有点和数字
您可以使用下面涵盖您所有案例的选项最小化您的正则表达式。
结果是更快的正则表达式
\b(?)
\b
(?
基准
Regex1: \b(?<!\.)\d{3}(?:\.\d{2})?\b(?!\.)
Completed iterations: 50 / 50 ( x 1000 )
Matches found per iteration: 2
Elapsed Time: 1.18 s, 1175.88 ms, 1175882 µs
Matches per sec: 85,042
Regex2: \b(?<!\d\.)\d{3}(?:\.\d{1,2})?\b(?!\.\d)
Completed iterations: 50 / 50 ( x 1000 )
Matches found per iteration: 2
Elapsed Time: 1.31 s, 1307.20 ms, 1307199 µs
Matches per sec: 76,499
Regex1:\b(?也许\b(??看哦,是的!太好了!非常感谢你!我应该在花半天时间自己找出答案之前先问一下;-)好的,所以\b(?也可以用,它更高效、更短。\b(?除非被接受的答案将接受“123.4”,但您的答案不会。根据OP尝试的解决方案,您的答案似乎应该接受。
Regex1: \b(?<!\.)\d{3}(?:\.\d{2})?\b(?!\.)
Completed iterations: 50 / 50 ( x 1000 )
Matches found per iteration: 2
Elapsed Time: 1.18 s, 1175.88 ms, 1175882 µs
Matches per sec: 85,042
Regex2: \b(?<!\d\.)\d{3}(?:\.\d{1,2})?\b(?!\.\d)
Completed iterations: 50 / 50 ( x 1000 )
Matches found per iteration: 2
Elapsed Time: 1.31 s, 1307.20 ms, 1307199 µs
Matches per sec: 76,499