Regular expression guaranteed to fail

Eric Brunel eric_brunel at despammed.com
Tue Aug 24 12:50:20 EDT 2004


Hallvard B Furuseth wrote:
> Greg Chapman wrote:
> 
>>Why not just "(?!)": this always fails immediately (since an empty pattern
>>matches any string, the negation of an empty pattern match always fails).
> 
> 
> It's fine for re.match.
> 
> 'Why not?': Because I'd expect re.search to walk through the entire
> string and check if each position in the string matches that regexp.
> Unfortunately, a little timing shows that that happens with _every_
> regexp suggested so far.  Long strings take longer for each of them.
> (Except Jeremy's solution, of course, which avoids the whole problem.)
> r'\A(?!)' or r'\Ax\A' didn't work either.
> 
> Anyway, I note that r'x\A' beats all the other regexps suggested so far
> with a factor of 20 when searching 's'*10000.

And when searching 'x'*10000? Since there is an 'x' in the re, it may change 
things a lot...
-- 
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com




More information about the Python-list mailing list