Regular expressions

Dennis Reinhardt DennisR at dair.com
Tue Oct 28 14:47:33 EST 2003


> That's not what I want.  If I have yipee as "kdasfjh", then I want to
> compare to all combinations, so that there will be a match when it
compares
> it with say when line is "fas" because line has all those letters in
yipee.
> But "fass" will not match because yipee does not have two "s"'s.

Were you to alphabetize both your regex and line, then the question is can
"afs" or "afss" match the pattern "adfhjks".  By manipulating the lines
strings "a.*f.*s" or "a.*f.*s.*s", you will see that the first line
instance matches the regex and the second does not.

Notice that the regex must be a string (not compiled) *and* this trick runs
the regex backwards, matching the line (with embedded ".*") against the
pattern and not the normal direction.  There may be more straightforward
ways to do this but this is the regex solution which occurs to me.

On second thought, the regex "\A(a|)(d|)(f|)(h|)(j|)(k|)(s|)\Z" will match
"fas" but not "fass".

-- 
Dennis Reinhardt
DennisR at dair.com   http://www.spamai.com?ng_python






More information about the Python-list mailing list