Help with a REGEX
I've got a little bit of a problem... I'm in the middle of programming the forums and I'm just trying to implement some BBCode so people can post things without being able to trash the pages with HTML.
Seeing as I can't find a prefab solution which does BBCode under ASPNET, I'm making my own
I've got a little bit of a problem... I'm in the middle of programming the forums and I'm just trying to implement some BBCode so people can post things without being able to trash the pages with HTML.
Seeing as I can't find a prefab solution which does BBCode under ASPNET, I'm making my own with regular expressions... The problem is: I want to do this easily but have it so it works well.
Say you have some BBCode like this:
[b]This should be bold.[/b]
Naturally, I want to search for an open an close tag. Simple enough. But what if someone doesn't close a tag? I need to seach for open tags from the front and search for their closing tags from the back... Getting a little more complicated.
I'd also (for performance sake) not like to have 150 REGEXes for each tag rather:
[*]content[\*]
So I match anything that looks like a tag and then I can iterate through the tags to see what I'm allowing and what to replace it with. For the more complex tags, such as URLs, I'll have a separate REGEX.
Here's the work in progress:
\[(?<tag>\w+)\].*\[/\k<tag>\]
It matches the outermost tags but it only matches one set of tags... Therefore if you try to parse [b][u]RAWR[/u][/b], it only gets b.