Jump to content
SubSpace Forum Network

Recommended Posts

Posted (edited)

Hello,

 

I have a general question about Regular Expressions.

 

I am using Notepad++ and I want to replace a line for another in 100+ opened documents.

 

This is what I have:

 

../Images/image-11.jpeg

 

I want to replace it to something like this:

 

../Images/image-11.jpeg

 

Q: how do I keep the img tag as is and remove the p tags in all opened documents (notice that the img class changes in each document)?

 

P.S: I used (

) to capture the opening p tags

 

Thanks,

Edited by Seriel Killer
Posted
Hi,
 
Assuming I'm reading this correctly, you want to strip the

tags surrounding the tag, right?  If that's the case, then you really only need to capture the tag.

 
This particular regular expression may do what you want...note that this uses a quick and dirty method of picking up html tags, and would fail if there were another ">" character inside the tag.
<p[^>]*>(<img[^>]+\/>)<\/p>

If this doesn't quite work for you, then you may want to try experimenting with http://regexpal.com/ ...I've found the highlighting to be quite helpful.

 

Hopefully that helped. :)
Posted (edited)

Yes I do want to strip those

tags away but I don't see your implementation works.

 

I do:

 

1. Find: 

[^>]*>([^>]+\/>)<\/p>

2. Replace with: ""

 

That would strip away those tags? no, it would simple find all those lines and replace them with nothing. if I put "([^>]+\/>)" in the replace area it would know what to replace with?

Edited by Seriel Killer
Posted

Try replacing it with "$1".

 

You will not be able to use regular expressions if the html gets more complex though. In that case you would need a DOM parser, such as the one found in your browser, or by making for example a simple node.js script.

Posted (edited)

Sweet as! that helped a lot, thanks everyone!

 

EDIT: Bargeld, only $1 keeps the original and replaces the other tags you choose, thanks.

Edited by Seriel Killer
×
×
  • Create New...