How to insert string in each match using RegEx iterator
roy at panix.com
Wed Jun 10 06:19:08 CEST 2009
<cb258e51-8c54-4b33-9b88-f23fc70a353a at z14g2000yqa.googlegroups.com>,
"504crank at gmail.com" <504crank at gmail.com> wrote:
> By what method would a string be inserted at each instance of a RegEx
> 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 you are saying, you should be looking at the
join() string method. I'm thinking something along the lines of:
groups = match_object.groups()
newstring = " INSERT ".join(groups)
More information about the Python-list