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

后端 未结 3 1449
感情败类
感情败类 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:13

    Use a regex that doesn't have any dots:

    ^[^.]*$
    

    That is zero or more characters that are not dots in the whole string. Some regex libraries I have used in the past had ways of getting an exact match. In that case you don't need the ^ and $. Having a language in your question would help.

    By the way, you don't have to use a regex. In java you could say:

    !someString.contains(".");
    

提交回复
热议问题