如何只匹配不包含点的字符串(使用正则表达式) [英] How to match only strings that do not contain a dot (using regular expressions)
问题描述
我试图找到一个正则表达式,它只匹配不包含点的字符串,例如它匹配 stackoverflow
、42abc47
或 a-bc-31_4
但不匹配:.swp
、stackoverflow
或 test.
.
I'm trying to find a regexp that only matches strings if they don't contain a dot, e.g. it matches stackoverflow
, 42abc47
or a-bc-31_4
but doesn't match: .swp
, stackoverflow
or test.
.
推荐答案
^[^.]*$
或
^[^.]+$
取决于您是否要匹配空字符串.某些应用程序可能会隐式提供 ^
和 $
,在这种情况下,它们是不必要的.例如:HTML5 input
元素的 pattern
属性.
Depending on whether you want to match empty string. Some applications may implicitly supply the ^
and $
, in which case they'd be unnecessary. For example: the HTML5 input
element's pattern
attribute.
您可以在 regular-expressions.info 站点上找到更多重要信息.
You can find a lot more great information on the regular-expressions.info site.
这篇关于如何只匹配不包含点的字符串(使用正则表达式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!