[Tutor] Regular Expression Misunderstanding
Kent Johnson
kent37 at tds.net
Fri Jul 14 12:55:17 CEST 2006
Steve Nelson wrote:
> On 7/14/06, John Fouhy <john at fouhy.net> wrote:
>
>
>> It doesn't have to match the _whole_ string.
>>
>
> Ah right - yes, so it doesn't say that it has to end with a b - as per
> your comment about ending with $.
>
The matched portion must end with b, but it doesn't have to coincide
with the end of the string. The whole regex must be used for it to
match; the whole string does not have to be used - the matched portion
can be a substring.
>
>> If you look at the match object returned, you should se that the match
>> starts at position 0 and is four characters long.
>>
>
> How does one query a match object in this way? I am learning by
> fiddling interactively.
The docs for match objects are here:
http://docs.python.org/lib/match-objects.html
match.start() and match.end() will tell you where it matched.
You might like to try the regex demo that comes with Python; on Windows
it is installed at C:\Python24\Tools\Scripts\redemo.py. It gives you an
easy way to experiment with regexes.
Kent
More information about the Tutor
mailing list