0

Several times recently I've wanted to create a regular expression that will never match any input (even an empty string). Some of the apparently most obvious ways are either very crude, turn out to have undesirable behaviour... or just plain don't work!

My provisional solution, which works fine for my particular case is simply a pattern of '\x00NEVERMATCHES\x00' (Python syntax for a string bracketed by two NUL bytes). It's self-documenting and, given the binary content, can never match my text-only input. What about the case where the input has no such restrictions?

A reading of the Javascript and Python regular expression docs didn't bring anything simple to mind. What would be your approach to this?

Solutions in any fairly generic regex syntax would be fine. My particular uses would be in Javascript and Python, but their regex syntaxes are pretty typical so I won't limit the answers unnecessarily at this point.

Peter Hansen
  • 19,290
  • 3
  • 45
  • 70

0 Answers0