javascript - How to alter a regex to be non-greedy (JS) -


i'm trying replace var tags attribute wrapped in square brackets

data.replace(/<var .*?="">(\d+)<\/var>/ig, '[[[$1]]]');

but not work if there multiple var tags. example,

<var id-0=""></var> responds <span id-1="">in <var num="">1</var> days</span>

will result in

[[[1]]] days</span>

but result need

<var id-0=""></var> responds <span id-1="">in [[[1]]] days</span></strong>

using <var [^=]*="">(\d+)<\/var>

regex101 - 1


in case there more 1 attribute or attribute has value num="something" above wouldn't work, instead, use <var( [^=]*="[^"]*")*>(\d+)<\/var> [[[$2]]] substitution.

regex101 - 2


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -