Prashant Bhanarkar Prashant Bhanarkar - 1 month ago 6x
Python Question

Find all lines beginning with a digit

What is the regex to extract all lines beginning with a digit?

I know the '^' character is used to match anything at the beginning of the line but I am not constructing it correct.

Here is what I have tried :



I'm guessing you want to match the entire the line but it is only matching the starting number. You need to include the greedy wildcard as well as the multiline argument to tell it you want to search many lines. Try:

re.findall('^[0-9]+.*', mystring, re.MULTILINE).