Regex - match data between nth space and stop at nth space

341 Views Asked by At

I am trying to capture/parse event log data, windows and linux using regex in a log collection tool. I can't seem to find a regex that tells me how to capture only data between the nth space and stop matching after the following nth space.

For example:

<11>Mar 7 09:55:54 blahblah blahblahblah textiwant blahblahblahblah

How do I capture only textiwant? I realize I can get to textiwant by (\S+ \S+ \S+ \S+ \S+) but I am baffled as to how to keep only textiwant, nothing before and nothing after.

Thank you!

1

There are 1 best solutions below

7
On

Make use of capturing groups and anchors:

^(?:\S+\s+){5}(\S+)

See a demo on regex101.com.