Page 1 of 1

Nested bbCode

Posted: Thu Jun 14, 2007 3:48 pm
by superdezign
I created a nice little bbCode pattern that I'm using to make my blog writing simpler and enable the ability for me to make some patterns for parsing my code, but I've run into a problem.

Nested tags.

Any tags within other tags are completely ignored. I could run the preg_match_all on the results also, but that seems... unorthodox to me. Does anyone know how this would be accomplished, or is that the only way?

By the way, in case anyone's interested, here's the regex pattern thus far:

Code: Select all

(\[([\w]+)(=([\w]+))?\])(.*?)(\[\/\2\])

Posted: Thu Jun 14, 2007 6:43 pm
by feyd
preg_match_all() the individual tags instead of them as a whole.

Posted: Thu Jun 14, 2007 6:47 pm
by superdezign
How would I determine when the bbCode ended, then?

Posted: Thu Jun 14, 2007 7:07 pm
by feyd
Maintain nesting counters.

Posted: Thu Jun 14, 2007 7:34 pm
by superdezign
Ooh.

But if I did that, then why not preg_match_all the innards of other tags, and keep a counter that way?

Posted: Thu Jun 14, 2007 7:46 pm
by feyd
You wouldn't capture the entire nest. You'd capture the beginning and up to the first nested closing.

Posted: Thu Jun 14, 2007 7:54 pm
by superdezign
Gotcha. Back to work.