How to find and replace in the between tags in notepad++

find and replacenotepadregex

I have a problem about find and replace in notepad++.

I want to find a space+space in text and replace with just one space. But the area I want to find and replace is between tags (ex: <div>...</div>). My file is .xml so it has a lot of tags.

Best Answer

This should do the trick.

Find what:  +(?=[^<]*?</div>)

Replace with: 

Note that the Replace with actually has a single space in there.

Then Replace All.

Look ahead

Basically it's matching multiple spaces, i.e ' +', with a single space as long as the look-ahead doesn't find anything other than a </div> to end the expression. Instead of .*? it uses [^<]*? to make sure it doesn't match beyond any other tag marker.

It works on a simple test document but you might want to test it out first with yours.

Related Question