Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I combine a positive and negative condition in a regex?

I fairly new to regular expressions and need some help. I need to filter some lines using regex in Perl. I am going to pass the regex to another function so it needs to be done in a single line.

I want to select only lines that contain "too long"and that don't begin with "SKIPPING"

Here are my test strings:

SKIPPING this bond since maturity too long
TKIPPING this bond since maturity too long
SLAPPING this bond since maturity too long
Hello this maturity too long
this is too long
hello there

The regex rule should match the following on 'too long":

SKIPPING this bond since maturity too long
SLAPPING this bond since maturity too long
Hello this maturity too long
this is too long

and it should skip:

"hello there" because it doesn't contain 'too long'
"SKIPPING this bond since maturity too long" because it containst 'SKIPPING'

like image 485
autodidact Avatar asked Nov 30 '22 06:11

autodidact


1 Answers

/^(?!SKIPPING).*too long/
like image 113
chaos Avatar answered Dec 06 '22 08:12

chaos