slevithan/xregexp

Issue with flags

john5634 opened this issue · 1 comments

Hello! I am using XRegExp to deal with an old version of firefox that our javascript tool must work with. The version of firefox does not allow s (dotall) and negative look behinds.

I tried to use XRegExp to solve that issue, but it seems it does not keep the "s" flag when generating a regex object from a string.

Regex I used was /.*?</CD>/gms (g for global, m for multiline, s for dotall)

With the text of:
"Hello
Hello2
Hello3"

Should result in 2 matches match0 = "Hello"
and match1 = "Hello2"

But for some reason it doesent! the regex generated when I print the regex object removes the s flag!!!

Why would it remove the s flag?

Again I am using XRegExp to deal with an old version of Firefox that I must use. any version of Firefox before version 50 will show the results for sure!

Nonnative XRegExp flags (s, x, n, A, etc.) don't show up as native properties, but the generated regexes are rewritten to behave as if they're present.

XRegExp('.').test('\n'); // false
XRegExp('.', 's').test('\n'); // true

var regex = XRegExp('.', 's');
// you can see it here if you really need to
regex.xregexp.flags; // 's'

Updating the ES6+ native RegExp.prototype.flags property to include nonnative flags might be a good idea for future versions.

PS: You can manually use [\S\s] instead of . in any regex to behave as if the s flag is enabled, and you don't need XRegExp to do that.