Originally posted by drawmack
Weed,
I'd like to addapt this to something that I need but I'm not sure I understand the regular expression well enough to do so. Could you please explain the regex?
Well, everything's covered in the manual, but...
# is the start of the regexp. / is traditional, but I wanted to use that in the regexp itself and I was too lazy to go \/.
< is the start of an HTML tag...
b[/b] ...which might be immediately followed with a /. We want to remember if it is or not, so we color=darkblue[/color] it.
b[/b] One or more wordlike-characters. \w is basically short for [a-zA-Z0-9_]. That covers the names all of the HTML tags. We remember this as well.
\b This is a "zero-width" match. It doesn't actually match any character in the string; instead it matches the boundary between a wordlike character and a nonworlike character - the beginning or end of a word, in other words. May not be strictly necessary in this particular instance, but it's convenient.
# The end of the regexp
e Executable modifier. Take the string produced by the replacement text and run it as PHP code, and use the result of that as the replacement string.
"'<$1'.strtolower('$2')" After the $1 and $2 have been substituted with the bits we remembered (the optional / and the tag name, respectively), this bit of code is evaluated to determine the string that will replace the matched text. In this case, a <, possibly followed by a /, and then a (lower-case) word.