Regular expression to extract any 4 digit number starting beginning with 5 from a text file using python

senheisen

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?

senheisen

regex = re.compile(r"\b(5\d{3})\b") is more exact

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Extract specific words from text in python using regular expression

extract number from string using regular expression

Extracting file names from text using regular expression Python

Using regular expression to extract number

extract number using regular expression

Find specific digit in a number using regular expression

Regular expression to extract chunks of text from a text file?

How can I extract number from text with regular expression

Creating regex to extract 4 digit number from string using java

R regular expression to extract TV show name from text file

.NET regular expression to extract 1-4 digit value from mixed character value

Regular expression to find values starting from beginning and after return

extract [+-] decimals from a text using jquery regular expression

Extract URLs from paragraph or block of text using a regular expression

How to extract text from a string using a regular expression in R?

How to get all the text from the beginning of a 12 digit number and group them using regex

How to modify phone number from a text file then print to the terminal using Sed and Extended Regular Expression?

Regular Expression to extract quantity with dimensions from text in Python

Process text file - Extract data starting with number

extract a number starting from some fix number from a given string using Regex expression

Extract number from text using Python

Extracting Datafram columns using regular expression from a big text file using python or R

regular expression to extract number from string

Regular expression for ten digit number

Using regular expression in python to extract a list of strings from a large string

Regular expression : extract text from middle of line

regular expression to extract JSON string from text

Using a regular expression validator to check for 11 digit number or empty

regular expression on python picking only one-digit number