Regex matching no strings

后端 未结 2 1757
既然无缘
既然无缘 2021-01-25 03:56

Does there exist a regular expression that matches no strings? If so, what is it?

To be precise, I\'m looking for a regular expression r such that the follo

相关标签:
2条回答
  • 2021-01-25 04:27

    If your regex engine supports lookahead (which Python's does):

    (?!)
    

    Otherwise something like this would work too:

    ^\b$
    

    A word break can't occur by itself!

    Or,

    $a^
    

    The end of the string can't match at the start of the string unless the string is empty, and we prevent it from being empty by requiring that we match at least one character.

    Then again, ^/$/\b are really just lookarounds in disguise.

    0 讨论(0)
  • 2021-01-25 04:39

    The following regex should match no strings. It will match any single character which is neither a whitespace character, nor a nonwhitespace character.

    [^\S\s]
    
    0 讨论(0)
提交回复
热议问题