How do I remove a part of a line that has a specific beginning and ends in Notepad ++?

Let's say, for example, I have HTML code made up of many elements that looks like

<div id="1-element" class="1-element">...</div>
<div id="2-element" class="2-element">...</div>
...
<div id="99-element" class="99-element">...</div>
<div id="100-element" class="100-element">...</div>
...

      

I only need to remove all parts class="*-element"

from the whole document, but leave div

s, id

and other things using regex in Notepad ++. How can i do this?

+3


source to share


3 answers


\bclass="\d+-element"

      



This should do it for you

+2


source


This works for me:

  • In Notepad ++, open the search boxes, select the replace tab.

  • Find what: \sclass="\d+-element"

  • Check regex.

  • Click Replace All.

  • And the result:

<div id = "1-element"> </div>



<div id = "2-element"> ... </div>

<div id = "99-element"> </div>

<div id = "100-element"> </div>

+1


source


You can use the following regular expression replacement:

Find that :class="[^"]+-element"(?=[^>]*>)

Replace : empty string

Note that [^"]+

will match anything, not just the numbers before -element

and (?=[^>]*>)

lookahead make sure we remove the attribute class

inside the node.

enter image description here

+1


source







All Articles