ridgerunner wrote:Why in the world would you want to allow *nested* BBCodes within a BBCode attribute/parameter?
Here's an example:
Forum Rules wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
Notice the link in the quoter name.
I'll take a swing at commenting it...
Code: Select all
/
\[ # tag opening
(%s) # tag name
( # optional parameter
=( # either...
[^[]
|\[(?!
\/?\\1(=.+?)?\]
)
|(?R) # a repeat of this pattern
)+ # occuring lots of times
)? # parameter optional
\] # tag closing
(
(?:
[^[]
|\[(?!
\/?\\1(=.+?)?\]
)
|(?R)
)+
)
\[\/\\1\] # end of tag
/six
The uncommented zones are parts I don't understand the logic behind. Ha, look how the flags came out.
ridgerunner wrote:Test your regex on badly formed BBCode (Missing and/or extra square brackets in various locations). Its relatively easy to get a regex to perform well on well-formed input which matches. Be sure that it performs well with non-matches/near-matches as well (non-matches are typically where you can get into trouble with catastrophic backtracking).
Test your regex on large subject texts; both well-formed and badly-formed (with certain classes of regex, PHP/PCRE blows up quickly with excessive recursion when applied to larger strings).
That's a good suggestion. I'll do that when it's working.
ridgerunner wrote:You are stretching the limits of a single regex (to put it mildly). I hesitate to use the phrase: "I think this is impossible" - but on first glance, I'm tempted to say just that...
It does seem like it's bordering on the impossible, but I'm only trying to make it do what it already does, just in a different spot.
ridgerunner wrote:That said, I have to say you are braver than I!
I thought you were the resident regular expression wizard! I'm no expert, I just try to
look like I am
