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

Python: Searching for date using regular expression

I am searching for date information, in the format of 01-JAN-2023 in a extracted text, and the following regular expression didn’t work. Can \b and \Y be used this way?

import re

rext = 'This is the testing text with 01-Jan-2023'

match = re.search(r"\d\b\Y", rext)
print(match)

>Solution :

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

import re

rext = 'This is the testing text with 01-Jan-2023'

match = re.search(r"\d+-\w+-\d+", rext)
print(match)
<re.Match object; span=(30, 41), match='01-Jan-2023'>
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