Regex Mismatch: Searching Anywhere For Certain Number Of Digits
I am trying to match values that come in this format: , ####-####-####-####### , ####-########-##### , ######-###-#-###-##-#-#### , ##-####-#####-#-###### For example: 2018-03-10,
Solution 1:
data = '2018-03-10, 354687-56987-314, 2018123-02-10-2019, 10-20-20232316'
re.findall(r'[^, ]*\d{5,}[^,]*',data)
Out[847]: ['354687-56987-314', '2018123-02-10-2019', '10-20-20232316']
EDIT
from the examples given the regex \S*\d{5,}[^,\s]*
can be used
Solution 2:
import re
text = "2018-03-10, 2018123-02-10-2019, 10-20-20232316"
re.findall(r'\w+(?:-\w+)+',text)
Solution 3:
Try the following regex. This will capture anything with 5 or more consecutive digits.
r'.*(\d{5,}).*'
Post a Comment for "Regex Mismatch: Searching Anywhere For Certain Number Of Digits"