re.match
Bob Cannard
bob_cannard at mentor.com
Fri Mar 23 17:09:14 EST 2001
> Dave Brueck wrote:
> Hi Bob,
>
> '$' matches 'end of string', so you _can_ use re.match to test "Is this string a Thing".
Heh. I already knew that, Dave; apparently my original message
wasn't clear enough. My point was that there's no way to do it
without constructing a second regular expression, which is
inefficient and clumsy. What is wanted is something like:
def fullmatch(r, s):
return re.match(r + '$', s)
but which, by analogy with re.match, does not have the overhead
of constructing and compiling a new regular expression; which
works equally well whether r is a string or a compiled re; which
works regardless of whether or not r already has a $ at the end.
I'm just surprised that Python has a separate function for matching
at the start of a string but seems to lack one for matching an
entire string. The issue is efficient re-use of a compiled regular
expression in different situations, not "how to do this".
Cheers,
Bob.
More information about the Python-list
mailing list