I am quite new in regular expression so I am having confusion in replacing numbers inside an string.
a="12ab34cde56"
I want to replace it by 12abXXcde56
b="abc1235ef"
I want to replace it by abcXXXXef
c="1ab12cd"
I want to replace it by 1abXXcd
I am trying those in python and in php, but with no luck. This is what I had in my mind:
^([0-9]+)([a-z]+)(.*)([a-z]+)([0-9]+)$
You can use this regex to capture all digits that is not leading or trailing:
Then in Python, you can supply a function that replace the match with corresponding number of
X.For PHP, you can enable PREG_OFFSET_CAPTURE to know the position of the match, and loop through the list of matches and process them.
Note that with the regex above
" 5 ddds"will be changed into" X ddds"