Is there a regular expression that will never match any string?
Ask the question in two parts:
- Is there any theoretical regex that will never match any string (using a general syntax without any of the fancy stuff provided by modern regex)?
- Is there an easy way to use the C # Regex syntax to create a regex that will never match any string (all the fancy stuff included this time)?
NOTE. I am not referencing empty string matching (that would be simple, simple ""
).
Just like you can match any characters to [\s\S]
, you cannot match characters to [^\s\S]
(or [^\w\W]
, etc.).
Without multiline mode, the end usually doesn't appear before the start:
$.^
Or simpler, again without multi-line mode:
$.
With search engines, you can do all sorts of conflicting things:
(?=a)(?=b)
This forces the hero to be two different things at once, which, of course, is impossible.
You can use conflicting lookbehinds like
\w(?<!\w)
Here \w
will match any character of the word, and lookbehind (?<!\w)
will make sure the last character is not a word.