Notepad++ find string with a new-line and replace
Solution 1
Speaking specifically about the newline and double-tabs, using the Extended Searched Mode find:
\r\n\t\t
and replace with:
(blank, nothing, empty string)
And assuming you are wanting to remove the URL from the href, leaving a blank reference, you'll want to use the Regular expression Search Mode to find:
href=\"(insert-http-url-regex-here)\"
and replace with:
href=\"\"
Solution 2
AFAIK you can't use regular expression-replace over multiple lines (in Notepad++) so you have to make them one-liners first. Here is how to do that using a macro:
- Hit CTRL+F and enter
href=
then hit Enter and Escape - Start recording a macro (CTRL+SHIFT+R)
- Press Delete 3 times (once for linebreak, twice for tabs)
- Finish recording the macro (CTRL+SHIFT+R again)
- Hit F3 to search the next
href=
occurence. - Execute macro (CTRL+SHIFT+P)
- Continue with Step 5 until all occurences are replaced.
Note: If all your href=
appearences are the same, you can also put the search into the macro (i.e. switch steps 1 and 2) and execute the macro until everything is on one line.
Now you can do a search & replace with regular expressions (CTRL+H):
Search for: href=".*">
Replace with: href="">
Related videos on Youtube
Oliver Salzburg
Updated on September 17, 2022Comments
-
Oliver Salzburg over 1 year
[Notepad++ Question]
How do I use find-and-replace to replace the attribute of a series of tags using expression?
Case scenario:
Let's say I have a couple of lines of something like this:
<li><a title="Bla bla" href= "http://www.url.com/etc">Text</a></li>
And I want to replace them with this:
<li><a title="Bla bla" href="">Text</a></li>
Note the new line and double tabs on the original.
-
Doltknuckle over 14 yearsfor some reason, notepad++ uses the SciTE implementation of regular expression which is a line by line search pattern. That's why this is a two step process, you can't use regular expression in Notepad++ to find line breaks. You might want to check out Textpad if you are going to be doing this kind of work all of the time.
-
JMD over 14 yearsSure, but as I detailed in my answer you CAN find line breaks using Extended search mode. Is it a problem to run two steps? And while I did use and promote Textpad for years, I switched, and the asker asked specifically about Notepad++.