21

I need help regarding using negative lookahead. I am using Notepad++ and I want to delete all lines except the lines that contain <title>(.*)</title>

I tried a couple of things but that didnt work.

^.*(?!<title>).*</title>
^.*(?!<title>.*</title>)
Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
Atif
  • 10,623
  • 20
  • 63
  • 96

1 Answers1

28

You are close:

^(?!.*<title>.*</title>).*

By this regex ^.*(?!<title>.*</title>), the regex engine will just find some position that it cannot find <title>.*</title> (end of line is one such valid position).

You need to make sure that, from the start of the line, there is no way you can find <title>.*</title> anywhere in the line. That is what my regex does.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162