Search for something inside specific elements

It seems to me that this should be simple, but I can not find the answer on the Internet.

I want to search for something that is inside an element with a specific class using Notepad ++.

So, I want to find all instances of <div class="ex">blahablahablah</div> , it doesn't matter what is between the div. I want to be able to find and replace for them so that I can mass delete.

+4
source share
1 answer

Try the following:

 <div[^>]*>.*?</div> 

or if you just want divs with class="ex" as above

 <div class="ex">.*?</div> 

Edit: if you want to have more attributes in your div except the class, but want to make sure that it is a specific class, you can do it like this:

 <div[^>]*?class="ex"[^>]*>.*?</div> 

This will fit all below:

 <div class="ex">blah blah</div> <div class="ex" id="blah">blah blah</div> <div id="foo" class="ex">blah blah</div> <div id="foo" class="ex" style="bar">blah blah</div> 

I am just re-reading your question, and it seems you are trying to replace only what is inside the element, not the whole element. If you want to do this, you can do it as follows:

Find what: (<div[^>]*?class="ex"[^>]*>).*?(</div>)
Replace with: $1replaced$2

Now all your ex divs will only contain "replaced"

+2
source

Source: https://habr.com/ru/post/1493300/


All Articles