javascript - Recognizing Multple Sets of Opening Tag, Body, and Closing Tag in Regex -


i'm attempting develop function converts [bold]...[/bold] <b>...</b> forum. of right now, works when there 1 set of [bold]...[/bold], however, whenever second 1 added, regex not recognize end of first [bold] until second.

to illustrate, if put "[bold]hello[/bold], how [bold]today[/bold]?", should this:

hello, how today?

however, i'm getting this:

hello[/bold], how [bold]today?

below current function:

function formatbolds(str) {     output = output.replace(/(\[bold\])(.*)(\[\/bold\])/g, "<b>$2</b>"); } 

all need change .* non greedy .*?

function formatbolds(str) {     output = output.replace(/(\[bold\])(.*?)(\[\/bold\])/g, "<b>$2</b>"); } 
  • the problem .* greedy , tries match many characters possible, includeing first [/bold] , following [bold] until last [/bold]. ? makes non greedy, , halts matching @ minimum length match

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -