juergen d
juergen d

Reputation: 204766

Look-Around Regex having text in between

I have log entries and I want to find the rows containing [ERR] but not IsLocked.

Example rows:

12:54:30 [INF] [Thread 2] Program started
12:54:30 [ERR] [Thread 1] IsLocked  
12:54:30 [ERR] [Thread 3] Internal Error

I want to find the 3rd row only with my regex. I tried

\[ERR\](?!IsLocked)

But that does not work since there is text between [ERR] and IsLocked.

Upvotes: 0

Views: 80

Answers (1)

Rohit Jain
Rohit Jain

Reputation: 213253

You can do it like this:

\[ERR\]((?!IsLocked).)*$

It looks for the string following the next character, and if it's not IsLocked, it goes on to match next character. It does this pre-check for every character matched till the end.

Upvotes: 1

Related Questions