Re: How to insert string in each match using RegEx iterator

2009-06-13 Thread John S
On Jun 10, 12:13 am, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' > > Here's the code I started

Re: How to insert string in each match using RegEx iterator

2009-06-12 Thread Aahz
In article , 504cr...@gmail.com <504cr...@gmail.com> wrote: > >MRI scans would no doubt reveal that people who attain a mastery of >RegEx expressions must have highly developed areas of the brain. I >wonder where the RegEx part of the brain might be located. You want Friedl: http://www.powells.com

Re: How to insert string in each match using RegEx iterator

2009-06-11 Thread 504cr...@gmail.com
On Jun 10, 10:13 am, Peter Otten <__pete...@web.de> wrote: > 504cr...@gmail.com wrote: > > I wonder if you (or anyone else) might attempt a different explanation > > for the use of the special sequence '\1' in the RegEx syntax. > > > The Python documentation explains: > > > \number > >     Matches

Re: How to insert string in each match using RegEx iterator

2009-06-10 Thread Peter Otten
504cr...@gmail.com wrote: > I wonder if you (or anyone else) might attempt a different explanation > for the use of the special sequence '\1' in the RegEx syntax. > > The Python documentation explains: > > \number > Matches the contents of the group of the same number. Groups are > numbered

Re: How to insert string in each match using RegEx iterator

2009-06-10 Thread 504cr...@gmail.com
On Jun 10, 5:17 am, Paul McGuire wrote: > On Jun 9, 11:13 pm, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > match? > > Some might say that using a parsing library for this problem is > overkill, but let me just put

Re: How to insert string in each match using RegEx iterator

2009-06-10 Thread Brian D
On Jun 10, 5:17 am, Paul McGuire wrote: > On Jun 9, 11:13 pm, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > match? > > Some might say that using a parsing library for this problem is > overkill, but let me just put

Re: How to insert string in each match using RegEx iterator

2009-06-10 Thread Paul McGuire
On Jun 9, 11:13 pm, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > Some might say that using a parsing library for this problem is overkill, but let me just put this out there as another data point for you. Pypar

Re: How to insert string in each match using RegEx iterator

2009-06-09 Thread Peter Otten
504cr...@gmail.com wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' Have a look at re.sub(): >>> s = '123 abc 456 def 789 ghi' >>> re.com

Re: How to insert string in each match using RegEx iterator

2009-06-09 Thread 504cr...@gmail.com
On Jun 9, 11:35 pm, "504cr...@gmail.com" <504cr...@gmail.com> wrote: > On Jun 9, 11:19 pm, Roy Smith wrote: > > > > > In article > > , > > >  "504cr...@gmail.com" <504cr...@gmail.com> wrote: > > > By what method would a string be inserted at each instance of a RegEx > > > match? > > > > For exampl

Re: How to insert string in each match using RegEx iterator

2009-06-09 Thread 504cr...@gmail.com
On Jun 9, 11:19 pm, Roy Smith wrote: > In article > , > >  "504cr...@gmail.com" <504cr...@gmail.com> wrote: > > By what method would a string be inserted at each instance of a RegEx > > match? > > > For example: > > > string = '123 abc 456 def 789 ghi' > > newstring = ' INSERT 123 abc INSERT 456 d

Re: How to insert string in each match using RegEx iterator

2009-06-09 Thread Roy Smith
In article , "504cr...@gmail.com" <504cr...@gmail.com> wrote: > By what method would a string be inserted at each instance of a RegEx > match? > > For example: > > string = '123 abc 456 def 789 ghi' > newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' If you want to do what I think y

How to insert string in each match using RegEx iterator

2009-06-09 Thread 504cr...@gmail.com
By what method would a string be inserted at each instance of a RegEx match? For example: string = '123 abc 456 def 789 ghi' newstring = ' INSERT 123 abc INSERT 456 def INSERT 789 ghi' Here's the code I started with: >>> rePatt = re.compile('\d+\s') >>> iterator = rePatt.finditer(string) >>> co