如何只匹配不包含点的字符串(使用正则表达式) [英] How to match only strings that do not contain a dot (using regular expressions)

查看:26
本文介绍了如何只匹配不包含点的字符串(使用正则表达式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个正则表达式,它只匹配包含点的字符串,例如它匹配 stackoverflow42abc47a-bc-31_4 但不匹配:.swpstackoverflowtest..

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆