How to match only strings that do not contain a dot (using regular expressions)

后端 未结 3 1460
感情败类
感情败类 2020-11-30 08:58

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-

3条回答
  •  爱一瞬间的悲伤
    2020-11-30 09:25

    ^[^.]*$
    

    or

    ^[^.]+$
    

    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.

    You can find a lot more great information on the regular-expressions.info site.

提交回复
热议问题