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

6,600

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.

Share:
6,600

Related videos on Youtube

Tuan
Author by

Tuan

Updated on September 18, 2022

Comments

  • Tuan
    Tuan almost 2 years

    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.

    • Ramhound
      Ramhound over 10 years
      Use a Regular Expression: superuser.com/questions/132855/…
    • Jerry
      Jerry over 10 years
      Regular expressions are not quite suitable for xml or html data, but if your xml is quite simple, it shouldn't be too hard. Can you perhaps put an example in your question? What can break a regex find/replace will be nested tags.
    • Scott - Слава Україні
      Scott - Слава Україні over 5 years