re = /errorCode\s*\=\s*\\\"(?<errorCode>[^\\]+)/m
str = '{"stream":"stderr","logtag":"P","log":"10/May/2024:09:31:53 +1000 [dgbttrfr] [correlationId=] [subject=], ERROR au.com.jbjcbdj.o.fefewgr.logging.LoggingUtil - severity = \\"ERROR\\", DateTimestamp = \\"09/May/2024 23:31:53\\", errorCode = \\"PAY_STAT_ERR_0017\\", errorMessage = \\"Not able to fetch error\\","hostname":"ip-101-156-185.ap-southeast-2.internal","host_ip":"10.56","cluster":"nod/pmn08"}'
# 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