Regex matching no strings

后端 未结 2 1758
既然无缘
既然无缘 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.

提交回复
热议问题