python - How to remove everything after the last number in a string -


i have strings this:

w = 'w123 o456 t789-- --' 

my goal remove after last number, desired output be

w123 o456 t789 

it not same ending, -- -- 1 example.

import re  re.sub('(.*?)(\d)', '', w) 

gives me

'-- --' 

how can modify command removes part?

you can use:

>>> w = 'w123 o456 t789-- --' >>> re.sub(r'\d+$', '', w) 'w123 o456 t789' 

\d+$ remove 1 or more non-digit characters before end anchor $.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -