The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
HTML Nested Tag Replacement
Discuss HTML Nested Tag Replacement in the Regex Programming forum on Dev Shed. HTML Nested Tag Replacement Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 22nd, 2009, 10:05 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
HTML Nested Tag Replacement
Groove and I ran into an interesting question over on the PHP forum. There was a member who wanted to replace only CERTAIN span tags (with a particular class name) with <strong> tags, also replacing the corresponding closing span with a closing strong. When there are no nested tags at all, the application is a trivial regex. However, what about nested tags? What about a replaceable span with non-replaceable spans inside of it? What about nested replaceable spans?
Since this forum is pretty dead, I thought I'd posit the question here as well. Check out the various PHP solutions we've come up with. My very last post in that thread solves the problem for everything but a replaceable span inside another replaceable span.
What do you guys think? Is it possible in a regexp?
-Dan
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

December 22nd, 2009, 05:45 PM
|
 |
Moderator Emeritus
|
|
Join Date: Feb 2002
Location: Scottsdale, AZ
|
|
I still plan on solving this damn thing. 
|

December 22nd, 2009, 05:59 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Good luck to you! I'm still waiting for requinix to drop a regex bomb on us.
-Dan
|

December 22nd, 2009, 06:02 PM
|
 |
Moderator Emeritus
|
|
Join Date: Feb 2002
Location: Scottsdale, AZ
|
|
Quote: | Originally Posted by ManiacDan Good luck to you! I'm still waiting for requinix to drop a regex bomb on us.
-Dan |
Right? He'd be the one to do it, if it can be done. I know it's possible to write recursive regex (as well as look-forward and look-behind)... just don't have enough regex-fu to pull it off myself. Yet. 
|

January 6th, 2010, 01:35 PM
|
|
Registered User
|
|
Join Date: Jan 2010
Location: Norcross, GA
|
|
Hi, I'm new here, but I'll contribute my 2 cents.
In the traditional definition of regex, no, it's not possible. Regular expressions are supposed to be reducible to a finite state automata. The moment you add a register (in this case, a variable to remember what tag you're trying to match), you've cheated.
But that's all just boring textbook talk. Many regex engines let you "cheat". The .NET regex engine is my weapon of choice, and it has a built in construct called a "balancing group definition" that would accomplish exactly what you're trying to do: keep track of nested pairs (matching html tags).
I did a quick google search and didn't see an equivalent in PHP. But maybe you're better versed in PHP than I and can run with this. 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|