Thread: Regex examples
View Single Post
Old 01-12-2015, 11:06 AM   #455
mzmm
Groupie
mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.mzmm has not lost his or her sense of wonder.
 
mzmm's Avatar
 
Posts: 171
Karma: 86271
Join Date: Feb 2012
Device: iPad, Kindle Touch, Sony PRS-T1
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.
i use something like this to catch paragraph tags, either empty or containing only whitespace. it also catches nested tags, so things like

<p><i><b><br/></b></i></p>

Code:
(?s)<p[^>]*?>\s*?(?:<\w[^>/]*?>)*?\s*?(?:&nbsp;|*|<br(?:\s|\s/|/)?>)*?\s*?(?:</\w[^>/]*?>)*?\s*?</p>
Quote:
Originally Posted by 1v4n0 View Post
EDIT Looks like this one is working, though I'm not entirely sure why.

Code:
<[^/>]+>[ \n\r\t]*</[^>]+>
because it's looking for

Code:
<[^/>]+>
an opening and closing bracket containing one or more of anything except closing brackets or forward slashes

Code:
[ \n\r\t]*
followed by none or more spaces, newlines or tabs

Code:
</[^>]+>
followed by an opening and closing bracket containing one or more of anything except closing brackets or forward slashes

Last edited by mzmm; 01-12-2015 at 11:09 AM.
mzmm is offline   Reply With Quote