My code receives a RegExp object (out of my control). It isn't global but I need it to be.
At the moment I'm doing this:
if (!regex.global) {
var flags = 'g';
if (regex.ignoreCase) flags += 'i';
if (regex.multiline ) flags += 'm';
if (regex.sticky ) flags += 'y';
regex = new RegExp(regex.source, flags);
}
...because I can't figure out any other way.
regex.global
doesn't have a setter. regex.compile(new_pattern)
is deprecated in favour of new RegExp(new_pattern)
regex.flags
isn't a thingIs there a better way to do this?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With