I'm trying to build a bbcode parser, but I'm having quite some problems figuring out how to avoid matching too widely. For example I want to implement a [list] to conversion like this:
\[list\](.*)\[/list\]
would be replaced by this:
<ul>$1</ul>
This works fine, except if I have two lists where the regular expression matches the beginning tag of the first list and the ending tag of the second. So this
[list]list1[/list] [list]list2[/list]
becomes this:
<ul>list1[/list] [list]list2</ul>
which produces really ugly output. Any idea on how to fix this?