开发者

What regular expression can never match?

Merged with A Regex that will never be matched by anything.

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 r开发者_StackOverflowegex syntaxes are pretty typical so I won't limit the answers unnecessarily at this point.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜