Regular Expression AND mach

Fuzzyman michael at foord.net
Sat Mar 20 06:03:00 EST 2004


Jeff Epler <jepler at unpythonic.net> wrote in message news:<mailman.161.1079716498.742.python-list at python.org>...
> Regular expressions are not a good tool for this purpose.
> 
> Here's one bad solution:
> 
> def permutations:
>     raise NotImplementedException, "exercise for the reader"
> 
> def rxseq(seq):  # Return a RE that has seq[0] followed by seq[1] etc
>     return ".*".join(seq)
> 
> def rxand(seq):  # Return an RE that matches each permutation of seq
>     return "|".join([rxseq(p) for p in permutations(seq)])
> 
> This fails when one part can overlap another, for instance if
> word1="aba" and word2="b", "ab" or "ba".
> 
> You could also use a bunch of lookahead assertions, something like
>     (?=.*word1)(?=.*word2)
> but you'll also come to regret this choice.
> 
> Jeff
> PS If you liked these regular expressions and would like to buy more,
> visit e-bay where I'm selling a RE that matches multiples of 3 base 10.

Hmm... I'm not sure if I've been helped or not :-)
Thanks anyway.....

I've ended up just doing a search in the the database for the longest
word.... (which returns all songs containing that word) and then
checking hte text of *each* song for all the other
words...............

It's not noticeably slow (only 1800 songs)... 
If I do this again I might try and find a useful indexer..........

Odd that you can't do this easily with regular expressions - I suppose
it doesn't compile down to a neat test.... but then it's hardly a
complex search... OTOH I have *no idea* how regular expressions
actually work (and no need to find out)...

Regards


Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list