Re: re.sub and named groups

2009-02-11 Thread Rhodri James
On Wed, 11 Feb 2009 21:05:53 -, Paul McGuire wrote: On Feb 4, 10:51 am, "Emanuele D'Arrigo" wrote: Hi everybody, I'm having a ball with the power of regular expression Don't forget the ball you can have with the power of ordinary Python strings, string methods, and string interpolati

Re: re.sub and named groups

2009-02-11 Thread Paul McGuire
On Feb 4, 10:51 am, "Emanuele D'Arrigo" wrote: > Hi everybody, > > I'm having a ball with the power of regular expression Don't forget the ball you can have with the power of ordinary Python strings, string methods, and string interpolation! originalString = "spam:%(first)s ham:%(second)s" print

Re: re.sub and named groups

2009-02-11 Thread Shawn Milochik
> > Book recommendation: _Mastering Regular Expressions_, Jeffrey Friedl > -- > Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ I wholeheartedly second this! The third edition is out now. -- http://mail.python.org/mailman/listinfo/python-list

Re: re.sub and named groups

2009-02-10 Thread Aahz
In article <4c7158d2-5663-46b9-b950-be81bd799...@z6g2000pre.googlegroups.com>, Emanuele D'Arrigo wrote: > >I'm having a ball with the power of regular expression but I stumbled >on something I don't quite understand: Book recommendation: _Mastering Regular Expressions_, Jeffrey Friedl -- Aahz (a

Re: re.sub and named groups

2009-02-04 Thread Yapo Sébastien
> Hi everybody, > > I'm having a ball with the power of regular expression but I stumbled > on something I don't quite understand: > > theOriginalString = "spam:(?P.*) ham:(?P.*)" > aReplacementPattern = "\(\?P.*\)" > aReplacementString= "foo" > re.sub(aReplacementPattern , aReplacementString, the

Re: re.sub and named groups

2009-02-04 Thread Emanuele D'Arrigo
On Feb 4, 5:17 pm, MRAB wrote: > You could use the lazy form "*?" which tries to match as little as > possible, eg "\(\?P.*?\)" where the ".*?" matches: > spam:(?P.*) ham:(?P.*) > giving "spam:foo ham:(?P.*)". A-ha! Of course! That makes perfect sense! Thank you! Problem solved! Ciao! Manu --

Re: re.sub and named groups

2009-02-04 Thread MRAB
Emanuele D'Arrigo wrote: > Hi everybody, > > I'm having a ball with the power of regular expression but I stumbled > on something I don't quite understand: > > theOriginalString = "spam:(?P.*) ham:(?P.*)" > aReplacementPattern = "\(\?P.*\)" > aReplacementString= "foo" > re.sub(aReplacementPattern

re.sub and named groups

2009-02-04 Thread Emanuele D'Arrigo
Hi everybody, I'm having a ball with the power of regular expression but I stumbled on something I don't quite understand: theOriginalString = "spam:(?P.*) ham:(?P.*)" aReplacementPattern = "\(\?P.*\)" aReplacementString= "foo" re.sub(aReplacementPattern , aReplacementString, theOriginalString)