python - How to escape number in regex -


so replacing characters re module.
have string 'abc_def' , need add 1 after _.
doing this.

st = 'abc_def' re.sub(r'^(\w+_)('')(\w+)$',r'\11\3',st) 

but takes \11 11th captured group, not \1 , 1 separately.

btw r\1,1\3 works should, returns abc_,1def.

need !

you can use \g<number> instead of \number:

re.sub(r'^(\w+_)('')(\w+)$',r'\g<1>1\3',st) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -