Prashant Bhanarkar Prashant Bhanarkar - 11 months ago 55
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).