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

Tom Tucker tktucker at gmail.com
Sun Sep 16 15:32:37 CEST 2007


Yep, looks like it.

>>> line = 'us::blah blah2 1002 blah3'
>>> import re
>>> TAG_pattern = re.compile(r"(us::.*) .*(1002|1003).*$")
>>> if TAG_pattern.search(line):
...     print 'we have a match'
...
we have a match
>>>

>>> line2 ='us::blah blah2 1001 blah3'
>>> if TAG_pattern.search(line2):
...     print 'we have a match'
... else:
...     print 'no match found'
...
no match found



On 9/16/07, 王瘢雹超 <daniel.chaowang at gmail.com> wrote:
> hi,
>
> I want to match the regular expression from right to left, such as:
>
> TAG_pattern = re.compile(r"(us::.*) .*(1002|1003).*$")
> TAG_pattern.search(line)
>
> Does the search method support this?
>
> Thanks,
> Daniel
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


More information about the Tutor mailing list