So I am making a simple BBCode parser in JavaScript, nothing too fancy. I first need to get a regular expression that will match only BBCode and will only match the first and last occurrences of the tag. This will help with items that are nested in each other such as
[b][c red]This should output bold red text[/c][/b]
which should be parsed to
<span style="font-weight: bold;><span style="color: red;">This should output bold red text</span></span>
The current "Master" regex (the one that detects if there is any BBCode in the string) is as follows.
(\[{1}([^\[]{1,3})(| .*?)\]{1}(.*?)\[{1}(\/{1}[^\]]{1,3})\]{1})
Is there any way to alter this in order to detect only the first and last matches?
Note: I want to exclude wikilinks such as [[Main Page]]