Regular expression guaranteed to fail

Des Small des.small at bristol.ac.uk
Tue Aug 24 16:28:20 CEST 2004


Greg Chapman <glc at well.com> writes:

> 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).

I think we have a winner!

Des
thanks all the persons who contributed, of course.
-- 
"[T]he structural trend in linguistics which took root with the
International Congresses of the twenties and early thirties [...] had
close and effective connections with phenomenology in its Husserlian
and Hegelian versions." -- Roman Jakobson



More information about the Python-list mailing list