Hi, i tried to do not show "SPAM" in string below using that regex:
alert("{SPAM\nSPAM} _1_ {SPAM} _2_".replace(/{[\s\S]+}/gm, ""));
What i was supposed to see was "~1~ ~2~"
(or something like that) but i got just ~2~. Why?
Hi, i tried to do not show "SPAM" in string below using that regex:
alert("{SPAM\nSPAM} _1_ {SPAM} _2_".replace(/{[\s\S]+}/gm, ""));
What i was supposed to see was "~1~ ~2~"
(or something like that) but i got just ~2~. Why?
}
and {
are also elements of the character class [\s\S]
. You should avoid matching this by:
/{[^}]+}/g
so that the regex stops once the }
is found.