title: Python - Searching file lines for multiple patterns efficiently
body: <p>I am working on parsing a number of large files and want to be sure I'm doing it as efficiently as possible. One of the lines I am parsing looks like this (a Windows Security Event Log 4624):</p>
  
  <pre><code>Security/Microsoft-Windows-Security-Auditing ID [4624] :EventData/Data -&gt; SubjectUserSid = S-1-0-0 SubjectUserName = - SubjectDomainName = - SubjectLogonId = 0x0000000000000000 TargetUserSid = S-1-1-11-1111111111-1111111111-1111111111-1111 TargetUserName = johndoe TargetDomainName = TestDomain TargetLogonId = 0x0000000001111111 LogonType = 3 LogonProcessName = NtLmSsp  AuthenticationPackageName = NTLM WorkstationName = TestWorkstation LogonGuid = {00000000-0000-0000-0000-000000000000} TransmittedServices = - LmPackageName = NTLM V2 KeyLength = 128 ProcessId = 0x0000000000000000 ProcessName = - IpAddress = 1.1.1.1 IpPort = 11111 
  </code></pre>
  
  <p>What I want to know is, what is the most efficient way to pull multiple fields from that line? I could partition the line repeatedly until I reach each field I am interested in, but I feel like repeatedly looping over the line is a waste of time/resources.</p>
  
  <p>Is there an intelligent way to look at the line only once but pull out, for example, the following fields:</p>
  
  <pre><code>LogonType = 3
  TargetUserName = johndoe
  TargetUserSid = S-1-1-11-1111111111-1111111111-1111111111-1111
  </code></pre>
  
  <p>As an example, what I could do is repeat the following process:</p>
  
  <pre><code>part = line.partition('TargetUserName = ')[2]
  username = part.partition(' ')[0]
  </code></pre>
  
  <p>to get each field that I want (the above example getting me just the username), but again that feels inefficient to me.</p>
  
  <p>Is there a better way to handle it?</p>