odi assle odi assle - 11 months ago 41
Python Question

how to get all string lines using regular expression in python

I need to take all string line between


For example if output is:

8019 Warning Microsoft-Windows-DNS-Client **EndOfSource.** The system failed to register host (A or AAAA) resource records (RRs) for network adapter
with settings:

Adapter Name : {B50403AE-8D65-4933-9E8E-7149657E41CD}

Host Name : l-reg-8128

Primary Domain Suffix : mtl.labs.mlnx

DNS server list :,

Sent update to server : <?>

IP Address(es) :


The reason the system could not register these RRs was because of a security related problem. The cause of this could be (a) your computer does not have permissions to register and update the specific DNS domain name set for this adapter, or (b) there might have been a problem negotiating valid credentials with the DNS server during the processing of the update request.

You can manually retry DNS registration of the network adapter and its settings by typing 'ipconfig /registerdns' at the command prompt. If problems still persist, contact your DNS server or network systems administrator. See event details for specific error code information. **EndOfMessage.**

I try the following code:

import re
re.findall("EndOfSource. (.*) EndOfMessage.", output)


There are several issues here:

  • The .* is a greedy subpattern, while you need the lazy one, use .*?
  • The . does not match a newline by default, you need to enable a DOTALL mode with re.S or re.DOTALL
  • Dots must be escaped to match literal dots.


re.findall(r"EndOfSource\. (.*?) EndOfMessage\.", output, flags=re.S)