Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

re.sub() wildcard

Am I doing something incorrectly with wildcards? I am trying to trim anything that follows " > " but it is only trimming the " > "

import re
noteIndex = "5/10/22, 14:20 > Mr Frank"
subStrip = ' > *'
noteStrip = noteIndex.replace(", " , "/")
noteID = re.sub(subStrip , "" , noteStrip)
print(noteID)

My output ends up being "5/10/22/14:20Mr Frank" when I want it to be "5/10/22/14:20"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Short answer, * is not a ‘wildcard’ in regex. * means ‘match the preceding character (or character class) 0 or more times. So > * means match > followed by 0 or more spaces.

The ‘match anything’ wildcard character in regex is .. So >.* would match > followed by 0 or more of any character.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading