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

2007-09-17 Thread Kent Johnson
王超 wrote: > 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;

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

2007-09-16 Thread Kent Johnson
王超 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 hav

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

2007-09-16 Thread 王超
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::' Tom: Thank you. But the number of 'us::' terms varies, and kent's solution works w

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

2007-09-16 Thread 王超
The number of iterms - (us::.*?) - varies. When I use re.findall with (us::*?), only several 'us::' are extracted. Daniel On 9/16/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > > 王超 wrote: > > yes, but I mean if I have the line like this: > > > > line = """38166 us::Video_Cat::Other; us::Video_Ca

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

2007-09-16 Thread Kent Johnson
王超 wrote: > The number of iterms - (us::.*?) - varies. > > When I use re.findall with (us::*?), only several 'us::' are extracted. I don't understand what is going wrong now. Please show the code, the data, and tell us what you get and what you want to get. Here is an example: Without a group y

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

2007-09-16 Thread Kent Johnson
王超 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? What do you mean match from right to left? If you mean, match an re that is anc

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

2007-09-16 Thread 王超
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 S

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

2007-09-16 Thread Tom Tucker
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): ...

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

2007-09-16 Thread 王超
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@python.org http://