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

confusing white space (\s) and word characters (\w) interpretation in Google Apps Scripts #232

Closed
Brt-L opened this issue Feb 1, 2020 · 3 comments

Comments

@Brt-L
Copy link

Brt-L commented Feb 1, 2020

In the Wiki, RE2 syntax states:
\s whitespace (== [\t\n\f\r ])
\w word characters (== [0-9A-Za-z_])

... but in Google Apps Scripts, this gives different results:
var char = String.fromCharCode(160); // No-Break Space
var re1 = /[\t\n\f\r 0-9A-Za-z_]/;
var re2 = /[\s\w]/;
var check = ( re1.test(char) == re2.test(char) ) ;
=> false

... also with:
var char = String.fromCharCode(249); // ù

... and many more !

The difference is not there in Google Sheets functions asRegExMatch() and Google Form validation using RegEx. So is Google Apps Script using another engine with different syntax ?
Anyway, it's confusing !

@junyer
Copy link
Contributor

junyer commented Feb 1, 2020

Just to be clear, U+00A0 (NO-BREAK SPACE) and U+00F9 (LATIN SMALL LETTER U WITH GRAVE) aren't ASCII, but in RE2, \s and \w match ASCII only.

I imagine that Google Apps Script uses the JavaScript flavour of regular expressions, but please refer to https://developers.google.com/apps-script/support if you need further help with this.

@junyer junyer closed this as completed Feb 1, 2020
@Brt-L
Copy link
Author

Brt-L commented Feb 1, 2020

Did some more digging ...
Made an issue at http://issuetracker.google.com/issues/148664349
(so anyway RE2 working as it should ...)

@junyer
Copy link
Contributor

junyer commented Feb 2, 2020

Glad to hear. :)

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

2 participants