psms
psms

Reputation: 883

Regular Expression not containing

I need a regular expression that matches the following conditions:

logger(textthatdoesnotcontain|)

Example:

logger(sample log) // Match
logger(sample log | test) // Not Match

I have tried below regex, but not working:

logger(?!*\|.*)

Upvotes: 0

Views: 40

Answers (2)

PiGo
PiGo

Reputation: 149

logger\([^\|]+\) should do the trick

Or if you want to match whole lines

^logger\([^\|]+\)$

This accept any character except "|" between "logger(" and ")"

Upvotes: 3

Pushpesh Kumar Rajwanshi
Pushpesh Kumar Rajwanshi

Reputation: 18357

If you want your line to not match if it contains |, you can just use this regex,

^logger\([^|]*$

Demo

You don't need a negative look ahead when you want to fail the match just because of one character and can use negated character set for such use cases like this [^|]

Upvotes: 2

Related Questions