python - Replace leading digits with regex -


i have following string:

s= '<file_name>857173423paramount_funeral_in_berlin_audio.mov' 

how want remove leading digits (if there 4 or more consecutive digits) occur after string file_name>.

so far have:

>>> re.sub('\d+','', s) '<file_name>paramount_funeral_in_berlin_audio.mov' 

but of course not general enough cover such cases as:

s = '<file_name>12897878lionsgate_t2.mov' 

either use lookbehind:

(?<=<file_name>)\d+ 

or use capture group , reference in substitution:

(<file_name>)\d+ \1 

i saw "4 or more digits", can replace + {4,}. match 4+ digits, , default regex "greedy" , continue on , match of leading digits:

(?<=<file_name>)\d{4,} 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -