Thread: Regex examples
View Single Post
Old 01-12-2015, 11:09 AM   #456
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 80,190
Karma: 148951761
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by 1v4n0 View Post
How about a regex that finds everything that has the structure of

<AAAwhatever></AAA>

i.e. all empty html elements.

Or, even better, all elements that either are empty or that contain just a space.

EDIT Looks like this one is working, though I'm not entirely sure why.

Code:
<[^/>]+>[ \n\r\t]*</[^>]+>
Don't use this. It won't work. Sorry, but you cannot guarantee that it won't mess something up.

Take a look at the following line...

<p><span>This is some text.<span class="smallcaps">THIS IS MORE TEXT</span>. This is yet more text.</span> And finally the last bit of text.</p>

Can you use regex to get rid of the empty span without messing up the span that actually does something? I don't see how you can.
JSWolf is offline   Reply With Quote