I am using the follwoing to extract any 4 digit number starting beginning with 5 from a text file using python:
regex = re.compile("^5\d{3}")
and this apparently looks only at the beginning of a line and doesn't look further until the end of the line to find the matches.
So for a sample string of "At this period by adding 52000 more particles we reched the value of 5810 threads per molecule." it shows no match.
What is wrong with my regular expression?
regex = re.compile(r"\b(5\d{3})\b")
is more exact
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments