Regular expression guaranteed to fail

Greg Chapman glc at well.com
Tue Aug 24 10:16:48 EDT 2004


On 22 Aug 2004 20:07:51 +0200, Hallvard B Furuseth <h.b.furuseth at usit.uio.no>
wrote:

>Eric Brunel wrote:
>
>> I also looked for a never-matching re just a few days ago and ended up
>> with "^(?!$)$". It's certainly not more "standard" than yours, but I
>> find it a wee tad more readable (for a regular expression, I mean...):
>
>I think e.g. r'\Zx' and r'x\A' are more readable.  In particular the
>latter, but perhaps that causes Python to locate every 'x' in the string
>and then check if the string starts at the next character...

Why not just "(?!)": this always fails immediately (since an empty pattern
matches any string, the negation of an empty pattern match always fails).

---
Greg Chapman



More information about the Python-list mailing list