SVS Subspace Forums
[SOLVED] Regular Expresssions - Printable Version

+- SVS Subspace Forums (http://forum.svssubspace.com)
+-- Forum: Chaos Zone (http://forum.svssubspace.com/forumdisplay.php?fid=59)
+--- Forum: Chaos Discussion (http://forum.svssubspace.com/forumdisplay.php?fid=27)
+--- Thread: [SOLVED] Regular Expresssions (/showthread.php?tid=418)



[SOLVED] Regular Expresssions - SK+ - 11-30-2013

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:

 

<p class="block3"><img alt="Image" class="calibre6" src="../Images/image-11.jpeg" />


 

I want to replace it to something like this:

 

<img alt="Image" class="calibre6" src="../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 (<p class="block)[0-9]*(">) to capture the opening p tags

 

Thanks,




[SOLVED] Regular Expresssions - lightbender - 11-30-2013

<div>Hi,</div>
<div> </div>
<div>Assuming I'm reading this correctly, you want to strip the tags surrounding the <img> tag, right?  If that's the case, then you really only need to capture the <img> tag.</div>
<div> </div>
<div>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.</div>
<div>
<pre class="_prettyXprint">
<p[^>]*>(<img[^>]+\/>)<\/p></pre>
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.

 

</div>
<div>Hopefully that helped. Smile</div>



[SOLVED] Regular Expresssions - SK+ - 11-30-2013

Yes I do want to strip those tags away but I don't see your implementation works.

 

I do:

 

1. Find: <span style="color:rgb(0,0,136);"><p</span><span>[^</span><span style="color:rgb(0,0,136);">></span><span>]*>(</span><span style="color:rgb(0,0,136);"><img</span><span>[^</span><span style="color:rgb(0,0,136);">></span><span>]+\/>)<\/p></span>

<span>2. Replace with: ""</span>

 

<span>That would strip away those tags? no, it would simple find all those lines and replace them with nothing. if I put "</span>(<span style="color:rgb(0,0,136);"><img</span>[^<span style="color:rgb(0,0,136);">></span>]+\/>)" in the replace area it would know what to replace with?




[SOLVED] Regular Expresssions - JoWie - 11-30-2013

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.




[SOLVED] Regular Expresssions - Bargeld - 12-01-2013

Find:

<p class=(.*)><img alt=(.*) class=(.*) src=(.*) />


 

Replace:

<img alt=\2 class=\3 src=\4 />




[SOLVED] Regular Expresssions - JoWie - 12-02-2013

That fails if you have multiple per line though, because * is greedy. In that cause you could use instead:

<p class=(.*?)><img alt=(.*?) class=(.*?) src=(.*?) />




[SOLVED] Regular Expresssions - SK+ - 12-03-2013

Sweet as! that helped a lot, thanks everyone!

 

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