Giter Site home page Giter Site logo

Comments (1)

verhovsky avatar verhovsky commented on July 1, 2024

The issue is that there's a difference between JavaScript and PCRE syntax in these \p values and Regexr just parses them like PCRE, even when you tell it it's JavaScript.

PCRE allows

\pL
\p{L}
\p{Han}

Whereas JavaScript allows

\p{L}
\p{Script=Han}
\p{Letter}

(note it doesn't allow \pL)

In PCRE, some text by its own is treated as a Script/Script_Extension/General Category (and if it's not a matching possible value in any of the 3 then that's an error) and in JavaScript some text by its own is just as the General Category (and if it's not a valid General Category, i.e. \p{Han} is a Script not a General Category, then that's an error) so it has the extra Script=Han syntax which PCRE doesn't have, so the parser needs to know if it's parsing JavaScript or PCRE.

The error happens in here

parseUnicode(token, sub) {
// unicodescript: \p{Cherokee}
// unicodecat: \p{Ll} \pL
// not: \P{Ll} \p{^Lu}
let match = sub.match(/p\{\^?([^}]*)}/i), val = match && match[1], not = sub[0] === "P";
if (!match && (match = sub.match(/[pP]([LMZSNPC])/))) { val = match[1]; }
else { not = not !== (sub[2] === "^"); }
token.l += match ? match[0].length : 1;
token.type = "unicodecat";
if (this._profile.unicodeScripts[val]) {
token.type = "unicodescript";
} else if (!this._profile.unicodeCategories[val]) {
val = null;
}
if (not) { token.type = "not"+token.type; }
if ((!this._profile.config.unicodenegated && sub[2] === "^") || !val) {
token.error = {id: "unicodebad"}
}
token.value = val;
token.clss = "charclass"
return token;
};

from regexr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.