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.compile(r"(\d+\s)").sub(r"INSERT \1", s)
'INSERT 123 abc INSERT 456 def INSERT 789 ghi'

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to