Delete digits in Python (Regex) -


I am trying to remove all digits from a string. Although the next code is also removed in the form of the words contained in any word, and obviously I do not want this. I'm not trying many regular expressions.

Thank you!


  s = "This should not be b3 delet3d, but in the end the number is 134411" s = re.sub ("\ d +", "", s) / Code>  

Result:

This should not be deleted, but finally the number is

\ d +. & gt; & Gt; & Gt; S = "This should not be B3dlett 3D, but finally the number is 134411" gt; & Gt; & Gt; S = re.sub ("\ d +", "", s)> gt; & Gt; & Gt; S 'It should not be B3dlett 3D, but in the end, yes'

Edit: After observing the comments, I decided to give a more complete answer. I think this is the account for all the cases.

  s = re.sub ("^ \ d + \ s | \ s \ d + \ s | \ s \ d + $", "", s)  < / Pre> 

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -