Main Area and Open Discussion > Living Room
Regexp help
Josh:
Alright, I am trying to create a regexp that performs the following:
Selects an IP address from a line but only if the line starts with a pre-defined text string. There will be text in between the text string and the IP address -- I want to ignore the entire line except for the IP address. I know this is do-able but it is driving me nuts.
Any ideas?
Renegade:
^definedstring.+([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).+$
Or perhaps:
^definedstring.+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).+$
But, that should do it or at least give you enough to test & tweak. You'll have 1 capture group with the IP address.
Renegade:
This is better:
^definedstring.+([1-9][0-9]{0,2}\.[1-9][0-9]{0,2}\.[1-9][0-9]{0,2}\.[1-9][0-9]{0,2}).+$
Josh:
So...Here is a single line of what I am trying to filter:
SOME DATE TIME GROUP HERE :: CtrlChan Some more text here [192.192.192.192]
I want to filter out the IP address in any line that contains CtrlChan.
Josh:
Sample line
2014-10-10 19:28:01.110::ErrorMsg::CtrlChan Error_Decode [192.192.192.192]
If, and only if, the line has CtrlChan in it do I want to extract the IP address from the line. This will be a very large file (200+MB per file) with a large number of different entries.
Navigation
[0] Message Index
[#] Next page
Go to full version