regular expression - matches
Steve Holden
steve at holdenweb.com
Fri Jul 21 12:07:38 EDT 2006
John Salerno wrote:
> Simon Forman wrote:
>
>
>>Python's re.match() matches from the start of the string, so if you
>>want to ensure that the whole string matches completely you'll probably
>>want to end your re pattern with the "$" character (depending on what
>>the rest of your pattern matches.)
>
>
> Is that necessary? I was thinking that match() was used to match the
> full RE and string, and if they weren't the same, they wouldn't match
> (meaning a begin/end of string character wasn't necessary). That's wrong?
That's wrong. In this context match just means you got to the end of the
pattern. However, if you don't want to add the "$" to the end of the
patterns, you could instead check that
m.endpos == len(s)
where m is the match object and s is the subject string.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list