RegExp: Allow nested matches in a match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

preg_match_all() is about the only way to do it accurately, in an easier manor unless you have identifying marks on either end you can easier search for like in your last example. The only problem is, the markings must match exactly somehow.. not so fun to type when coding. Which is why using a more simple syntax and using preg_match_all() works well... if you must really get the block of data inside the tags..

a lexical parser wouldn't need that much information, typically.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

But the question still lies; How would the pattern to match tags with the same key work? Sorry, but I can't find any way to do it myself :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

#<pre-first-key(key)post-first-key>(.*?)<pre-next-key\\1post-next-key>#is
Post Reply