Thread: RegEx
View Single Post
Old 12-12-2007, 10:38 AM   #7 (permalink)
xenon
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

One more thing, though. How about recursivity in a regex rule? How does that work? I'm trying to make a simple BB code parser (just playing around), and something doesn't add up. Example:

Code:
/\[(b|i|u)(?:.+?)?\](.+?)\[\/\1\]/
would successfully match:

Code:
[b ]some text[/b ]
,

(without the spaces of course), but the following expression...

Code:
[b ]some [i ]text[/i ][/b ]
would leave me with:

Code:
some text[/i ]
That's when recursivity popped in my mind and I did a Google search. But I believe I don't use properly, or the back-references don't remain the same during a recursive operation, because this rule:

Code:
/\[(((b|i|u)(?:.+?)?)|(?R))\](.+?)\[\/\1\]/
, applied on the text introduced at the top, leaves me with:

Code:
some [i ]text[/i ]
Spooky
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote