仅匹配空格或字符串开头/结尾之间的整数的正则表达式 [英] Regex that matches integers in between whitespace or start/end of string only
本文介绍了仅匹配空格或字符串开头/结尾之间的整数的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用模式:\b\d+\b
,使用以下条目对其进行测试:
I'm currently using the pattern: \b\d+\b
, testing it with these entries:
numb3r
2
3454
3.214
test
我只希望它捕获 2 和 3454.它非常适合捕获数字单词,除了边界标志 (\b)
包括 "."
作为考虑作为一个单独的词.我尝试排除句点,但在编写模式时遇到了麻烦.
I only want it to catch 2, and 3454. It works great for catching number words, except that the boundary flags (\b)
include "."
as consideration as a separate word. I tried excluding the period, but had troubles writing the pattern.
基本上我想删除整数词,并且只删除它们.
Basically I want to remove integer words, and just them alone.
推荐答案
如果你只想匹配空格,你可以使用环视:
You could use lookaround instead if all you want to match is whitespace:
(?<=\s|^)\d+(?=\s|$)
这篇关于仅匹配空格或字符串开头/结尾之间的整数的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文