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

王超 daniel.chaowang at gmail.com
Sun Sep 16 16:01:41 CEST 2007


yes, but I mean if I have the line like this:

line = """38166 us::Video_Cat::Other; us::Video_Cat::Today Show;
us::VC_Supplier::bc; 1002::ms://bc.wd.net/a275/video/tdy_is.asf;
1003::ms://bc.wd.net/a275/video/tdy_is_.fl;"""

I want to get the part "us::MSNVideo_Cat::Other; us::MSNVideo_Cat::Today
Show; us::VC_Supplier::Msnbc;"

but re.compile(r"(us::.*) .*(1002|1003).*$") will get the
"1002::ms://bc.wd.net/a275/video/tdy_is.asf;" included in an lazy mode.

How can i filter it out in the re?

Thanks,
Daniel


On 9/16/07, Tom Tucker <tktucker at gmail.com> wrote:
>
> 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
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070916/83d55800/attachment.htm 


More information about the Tutor mailing list