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
Post a Comment