Question

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>)
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top