Prashant Bhanarkar Prashant Bhanarkar - 1 year ago 87
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 :


Answer Source

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).
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download