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 :

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'>

Leave a Reply