re = /(?P<event_message>A user account was unlocked\.)\s+Subject:\s+Security ID:\s+(?P<subject_security_id>.*?)\s+Account Name:\s+(?P<subject_account_name>.*?)\s+Account Domain:\s+(?P<subject_account_domain>.*?)\s+Logon ID:\s+(?P<subject_logon_id>.*?)\s+Target Account:\s+Security ID:(?P<target_security_id>.*?)\s+Account Name:\s+(?P<target_account_name>.*?)\s+Account Domain:\s+(?P<target_account_domain>.*)/
str = 'A user account was unlocked. Subject: Security ID: S-1-5-21-173871781-544419543-443003237-500 Account Name: Administrator Account Domain: AV Logon ID: 0x1E3AD Target Account: Security ID: S-1-5-21-173871781-544419543-443003237-1111 Account Name: test Account Domain: AV'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html