Regexp problem

MRAB python at mrabarnett.plus.com
Thu Jul 30 17:40:46 EDT 2009


Ethan Furman wrote:
> Marcus Wanner wrote:
>> On 7/30/2009 9:32 AM, Beldar wrote:
>>
>>> On 30 jul, 15:07, MRAB <pyt... at mrabarnett.plus.com> wrote:
>>>
>>>> Beldar wrote:
>>>>
>>>>> Hi there!
>>>>> I have a problem and i'm not very good at regular expressions.
>>>>> I have a text like "lalala lalala tiruri beldar-is-listening tiruri
>>>>> lalala" I need a regexp to get the 'beldar' part, the format is
>>>>> 'something-is-listening', i need to get the something part, use it in
>>>>> my code, and then replace the whole 'something-is-listening' for
>>>>> another string.
>>>>
>>>> \w+ will match a word and enclosing it in (...) will capture what was
>>>> matched:
>>>>
>>>>      m = re.search(r"(\w+)-is-listening", text)
>>>>      print "Captured '%s'" % m.group(1)
>>>>      print "Matched from %d to %d" % (m.start(), m.end())
>>>
>>>
>>> Ok, thank you all, it was very helpful!
>>
>> Wow, I really need to learn more about regexp...
>> Any tutorials you guys can recommend?
>>
>> Marcus
> 
> Mastering Regular Expressions
> Powerful Techniques for Perl and Other Tools
> By Jeffrey E. F. Friedl
> 
> Great book!
> 
+1

I have the first edition, seventh printing (December 1998). It refers to
the 'regex' module of Python 1.4b1, which was subsequently replaced by
the current 're' module and then removed from the standard library. I
hope it's been updated since then. :-)



More information about the Python-list mailing list