Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/./u and /[^x]/u matching surrogate halves individually #16

Closed
mathiasbynens opened this issue Jan 23, 2015 · 1 comment
Closed

/./u and /[^x]/u matching surrogate halves individually #16

mathiasbynens opened this issue Jan 23, 2015 · 1 comment

Comments

@mathiasbynens
Copy link
Owner

Reported by Marja Hölttä:

var string = '𝌆𝌆';
var match = string.match(/(....)/u);
console.log(match[1]);

I checked that the same behavior occurs for other character classes too, like this:

var string = 'a𝌆b';
var match = string.match(/a([^c][^c])b/u);
console.log(match[1]); // 𝌆

And as a bonus, it transforms /(.+)\1/u to this:

> r = /((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uDC00-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF])+)\1/
> r.test('𝜆𝌆𝌇') // code units: D835 DF06 D834 DF06 D834 DF07
true

…which is pretty surprising :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant