.class specific search and replace
Use notepad++ with regular expressions
- Open Notepadd++
- Press CTRL+H
- Select Regular expression as search mode
- Enter
^.*myClass.*$
under Find what and nothing under Replace with - Click Replace all
Cases where start and end strings are in different lines (Notepad 6.xx)
We use a workaround and temporary delete all carriage returns (+newlines).
This gives us a single long line where its much easier to use RegEx. Later we put the carriage returns back.
- Choose a unique string like
%%%NEWLINE%%%
which doesn't occur so far in your text.
Test it first with a simple CTRL+F search - Press CTRL+H and select Regular expression as search mode
- Find
\r\n
and replace with%%%NEWLINE%%%
. Click Replace all.\r\n
are special characters and stand for carriage return and newline. You get one long line.
Remember: From now on you can't use^
and$
anymore - Find
<div .*?myClass.*?</div>
and replace with nothing (Notice the space) - Find
%%%NEWLINE%%%
and replace with\r\n
to bring back our normal text structure
While writing my edit I noticed you have changed your question with a game breaker. This method (probably no RegEx method at all) won't work while you have nested <div></div>
tags. The RegEx engine can't know if it should stop at the 2nd, 3th or n-th </div>
Used RegEx
^ → line beginning
. → any single character
* → repeat previous pattern
.* → any characters as long as possible (greedy)
.*? → any characters as short as possible (non greedy)
$ → line end
Used resources
- http://markantoniou.blogspot.de/2008/06/notepad-how-to-use-regular-expressions.html
- http://www.scintilla.org/ScintillaDoc.html#Searching
- https://stackoverflow.com/questions/4398613/notepad-newline-in-regex