[Tutor] how to match regular expression from right to left

Kent Johnson kent37 at tds.net
Sun Sep 16 17:25:46 CEST 2007


王瘢雹超 wrote:
> kent:
> Thank you.  I got the right results with re.findall('(us::.*?);', line).
> 
> I used these codes before:
>  >>> TAG_pattern = re.compile(r"(us::.*?)")
>  >>> TAG_pattern.findall(line)
> and got the unwanted results 'us::'

That is because .*? will match the empty string. You have to put the ;
after it to force the match to extend.

Kent


More information about the Tutor mailing list