RE Help

Steve Holden steve at holdenweb.com
Fri Sep 21 15:23:09 EDT 2007


chris.monsanto at gmail.com wrote:
> On Sep 21, 2:44 pm, David <wizza... at gmail.com> wrote:
>>> data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
>>> x = re.compile('START.END', re.DOTALL)
>> This should work:
>>
>> x = re.compile('START(.*)END', re.DOTALL)
> 
> You'll want to use a non-greedy match:
> 
> x = re.compile(r"START(.*?)END", re.DOTALL)
> 
> Otherwise the . will match END as well.
> 
Only if there's a later END in the string, in which case the user's 
requirements will determine whether greedy matching is appropriate.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden

Sorry, the dog ate my .sigline




More information about the Python-list mailing list