I need to digest some bbcode with a Ruby regex.
I need to delimit the elements with the match command and use regexp /pattern/m to get rid of new lines.
For example, my bbcode in the line:
s="[b]Title[/b] \n Article text \n [b]references[/b]"
Then I use match to delimit the parts of the text, especially the Title and The Reference sections, which are between [b] and [/b] :
t=s.match(/\[b\](.*)\[\/b\]/m)
I use syntax (..) to catch a string in regexp, and I use \ to avoid special characters [ and ] . /m is to get rid of newline in line.
Then t[1] contains:
"Title[/b] \n Artucle text \n [b]references"
instead of "Title" . because the match does not stop at the first occurrence [/b] . And t[2] is zero instead of โReferencesโ for the same reason.
How can I distinguish between text parts enclosed between regular bbcode tags?
source share