New to Regex Examples I've seen show searching for very specific exceptions ie. specific letter combos.
What I want is to grab the 8th word no matter what comes before,no matter what those words are.
So the spaces are what designates 'words'
Sample line would be
Sep 20 11:13:18 10.50.3.100 Sep 20 11:13:15 DC1ASM1.dcl.greendotcorp.com Blah Blah Blah
I want to extract the host name, in this case "DC1ASM1.dcl.greendotcorp.com", which is always preceded by "Month, Day, Timestamp, IP, Month, Day, Timestamp" pattern.
Thanks Rex
I'm not 100% sure what version or flavor of regex you're using, so I'll avoid the look-behind and use a non-capturing group instead:
^(?:\S+?\s){7}(\S+)
That binds to the beginning of the line, ignores 7 consecutive patterns of [any character but whitespace] 1+ times] then [one single whitespsace character].
You can be more specific about "words" by using \w
instead of \S
if you so chose, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With