djr33
07-21-2007, 02:54 PM
I'm trying to understand regex more, so this is just an exploratory question.
Let's assume (without going into any security issues, here), that I wanted to parse BB code as html.
The format would be ... which would become <tag>...</tag>
My question is how to keep the middle of that, the name of the tag, and replace it in the output.
In other words, replace '[' followed by any letters/numbers, no spaces (assume no parameters for now) then ']' with '<', the middle bit (letters/numbers), then '>'.
The main question is how you keep the unknown match portion (any letters/numbers) and put that same portion into the output.
I hope the question is clear enough.
Or a simpler question would be "find any pattern of number-letter-number-letter in the page, then duplicate that three times with hyphens between".
On the page, for example, "1a1a" would become "1a1a-1a1a-1a1a"
Let's assume (without going into any security issues, here), that I wanted to parse BB code as html.
The format would be ... which would become <tag>...</tag>
My question is how to keep the middle of that, the name of the tag, and replace it in the output.
In other words, replace '[' followed by any letters/numbers, no spaces (assume no parameters for now) then ']' with '<', the middle bit (letters/numbers), then '>'.
The main question is how you keep the unknown match portion (any letters/numbers) and put that same portion into the output.
I hope the question is clear enough.
Or a simpler question would be "find any pattern of number-letter-number-letter in the page, then duplicate that three times with hyphens between".
On the page, for example, "1a1a" would become "1a1a-1a1a-1a1a"