Jotne
Jotne

Reputation: 41460

How to get negative lookahead in regex to accept more words

I am trying to get some data for Splunk.

From this:

this my line - Fine (R/S)
more date - I like this (not)
date - output (yes)

I like to get all data from - to the end of line, but not the data in parentheses if it contains not or yes, so data in group1 should be:

Fine (R/S)
I like this
output

I have tried some like this:

- (.+) (?!(not|yes))

But this gives:

Fine
I like this
output

Or This:

- (.+)(?!not)

Gives:

Fine (R/S)
I like this (not)
output (yes)

Upvotes: 3

Views: 1909

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174874

You may try this,

- ((?:(?!\((?:not|yes)\)).)*)(?=\s|$)

DEMO

or

- (.*?)(?=\s+\((?:not|yes)\)|$)

This would capture all the chars until a space(yes) or space(no) or end of the line is reached.

DEMO

Upvotes: 3

Related Questions