conditional regex with Parens in the test string
Posted: Mon Nov 16, 2009 10:38 am
Hello,
I am trying to parse a string that contains an ip address \ dns name with or without a port. I have the code to get the ip address / dns name conditionally but my issue is that after the port there could be a string containing a paren "(".
My regex is (?([a-zA-Z0-9.-]+\/+[a-zA-Z0-9.-])(.*)\/(.*)|(.*)())\sby\saccess-group\s\"(.*)\"
My sample strings are:
mail.store.tn/456 (type 8, code 0) by access-group "OUT_IN" [0x0, 0x0]
mail.business.com (type 0, code 0) by access-group "ptv_outside" [0xb6baabe9, 0x0]
111.222.0.44 by access-group "inside" [0x0, 0x0]
What I need to capture in the groups are the ip / dns names, the ports if they exist and whatever is in the "". My problem is that with the above regular expression the "(Type X, code 0)" in the first two test strings are attached to the port / dns name and I want them removed. I have tried changing the conditional "Yes" to be (.*)\/(.\d) to only capture the digits after but that is failing (I am using Expresso to test my regex).
Any help would be greatly appreciated.
Thanks.
I am trying to parse a string that contains an ip address \ dns name with or without a port. I have the code to get the ip address / dns name conditionally but my issue is that after the port there could be a string containing a paren "(".
My regex is (?([a-zA-Z0-9.-]+\/+[a-zA-Z0-9.-])(.*)\/(.*)|(.*)())\sby\saccess-group\s\"(.*)\"
My sample strings are:
mail.store.tn/456 (type 8, code 0) by access-group "OUT_IN" [0x0, 0x0]
mail.business.com (type 0, code 0) by access-group "ptv_outside" [0xb6baabe9, 0x0]
111.222.0.44 by access-group "inside" [0x0, 0x0]
What I need to capture in the groups are the ip / dns names, the ports if they exist and whatever is in the "". My problem is that with the above regular expression the "(Type X, code 0)" in the first two test strings are attached to the port / dns name and I want them removed. I have tried changing the conditional "Yes" to be (.*)\/(.\d) to only capture the digits after but that is failing (I am using Expresso to test my regex).
Any help would be greatly appreciated.
Thanks.