I'm trying to write some regex that will parse information from alerts generated by Hyperic HQ. The alerts come in as emails with a subject line like:
"[HQ] !!! - Alert: My Demo Website Alert Resource: demo.myserver.net Apache Web Server State: fixed"
To cut a very long story short, I need to be able to consistently grab the "Apache Web Server" part, regardless of the hostname which may not even be present. I do know that the hostname will always end "myserver.net" though.
The regex I have is:
/Resource:\s.*(?<=mydomain.net)?\s(.*)\s(?=State)/
I was expecting that this would match zero or more characters between "Resource:"
and "State:"
, optionally following (but not including) a hostname.
Unfortunately, what it returns is "Server"
, i.e. the last word of the bit I want to match. This happens regardless of whether the hostname is in the string.
Can anyone help?
EDIT: Solution as supplied by Chad below
/Resource:\s(?:.*.myserver.net)?(.*)\sState/