1

I have this regex for Notepad++ which works to find the strings I am supposed to find which are all lines ending each with a number in brackets. ^.*\(\d*\)\r\n Problem is: Those are the lines I want to keep with a regex find & replace where I erase the other lines.

I tried

^.*?(?!\(\d*\))\r\n
^.*?(?!(\(\d*\)))\r\n
(?!(^.*?\(\d*\)\r\n))

None of these seem to work (or not work correctly).

What am I doing wrong?

1
  • 1
    welcome to stackoverflow Simone! any example of the lines in question? sample input would be nice to explore.
    – Bagus Tesa
    Commented Jul 8 at 9:03

1 Answer 1

1

I think this regex should only capture lines that does not end with numbers with parenthesis at the end:

^(?!.*\(\d+\)$).*$

Demo

  • ^ asserts position at start of a line
  • (?!.*\(\d+\)$) negative look ahead to see if the line not ends with number inside parenthesis.
  • .* mathces the full line
  • $ asserts position at the end of a line
1
  • 1
    Thanks! This worked. I was just not thinking about repeating the query after the lookahead. I thought it was needed only before of it, for some reason. Me dumb. Cannot upvote because I do not have reputation, but... uh.... you have my ghostly +1. Commented Jul 8 at 9:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.