├── .nvmrc
├── .travis-github-deploy-key.enc
├── .editorconfig
├── .gitignore
├── package.json
├── table-nonbinary-unicode-properties.html
├── .travis.yml
├── table-unicode-general-category-values.html
├── table-binary-unicode-properties.html
├── spec.html
├── README.md
└── table-unicode-script-values.html
/.nvmrc:
--------------------------------------------------------------------------------
1 | 6
2 |
--------------------------------------------------------------------------------
/.travis-github-deploy-key.enc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tc39/proposal-regexp-unicode-property-escapes/HEAD/.travis-github-deploy-key.enc
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = tab
6 | end_of_line = lf
7 | insert_final_newline = true
8 | trim_trailing_whitespace = true
9 |
10 | [{README.md,package.json,spec.html,.travis.yml}]
11 | indent_style = space
12 | indent_size = 2
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | package-lock.json
2 |
3 | dist
4 |
5 | # Installed npm modules
6 | node_modules
7 |
8 | # Folder view configuration files
9 | .DS_Store
10 | Desktop.ini
11 |
12 | # Thumbnail cache files
13 | ._*
14 | Thumbs.db
15 |
16 | # Files that might appear on external disks
17 | .Spotlight-V100
18 | .Trashes
19 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "scripts": {
4 | "test": ":",
5 | "build": "mkdir -p dist; ecmarkup --verbose spec.html dist/index.html --css dist/ecmarkup.css --js dist/ecmarkup.js"
6 | },
7 | "devDependencies": {
8 | "@alrra/travis-scripts": "^3.0.1",
9 | "ecmarkup": "^3.12.0"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/table-nonbinary-unicode-properties.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
38 |
6 |
9 |
10 | Property name and aliases
7 | Canonical property name
8 |
11 |
19 |
12 |
17 |
13 |
16 | `General_Category`
18 |
20 |
28 |
21 |
26 |
22 |
25 | `Script`
27 |
29 |
37 |
30 |
35 |
31 |
34 | `Script_Extensions`
36 |
4 |
5 |
357 |
6 |
9 |
10 | Property value and aliases
7 | Canonical property value
8 |
11 |
19 |
12 |
17 |
13 |
16 | `Cased_Letter`
18 |
20 |
28 |
21 |
26 |
22 |
25 | `Close_Punctuation`
27 |
29 |
37 |
30 |
35 |
31 |
34 | `Connector_Punctuation`
36 |
38 |
47 |
39 |
45 |
40 |
44 | `Control`
46 |
48 |
56 |
49 |
54 |
50 |
53 | `Currency_Symbol`
55 |
57 |
65 |
58 |
63 |
59 |
62 | `Dash_Punctuation`
64 |
66 |
75 |
67 |
73 |
68 |
72 | `Decimal_Number`
74 |
76 |
84 |
77 |
82 |
78 |
81 | `Enclosing_Mark`
83 |
85 |
93 |
86 |
91 |
87 |
90 | `Final_Punctuation`
92 |
94 |
102 |
95 |
100 |
96 |
99 | `Format`
101 |
103 |
111 |
104 |
109 |
105 |
108 | `Initial_Punctuation`
110 |
112 |
120 |
113 |
118 |
114 |
117 | `Letter`
119 |
121 |
129 |
122 |
127 |
123 |
126 | `Letter_Number`
128 |
130 |
138 |
131 |
136 |
132 |
135 | `Line_Separator`
137 |
139 |
147 |
140 |
145 |
141 |
144 | `Lowercase_Letter`
146 |
148 |
157 |
149 |
155 |
150 |
154 | `Mark`
156 |
158 |
166 |
159 |
164 |
160 |
163 | `Math_Symbol`
165 |
167 |
175 |
168 |
173 |
169 |
172 | `Modifier_Letter`
174 |
176 |
184 |
177 |
182 |
178 |
181 | `Modifier_Symbol`
183 |
185 |
193 |
186 |
191 |
187 |
190 | `Nonspacing_Mark`
192 |
194 |
202 |
195 |
200 |
196 |
199 | `Number`
201 |
203 |
211 |
204 |
209 |
205 |
208 | `Open_Punctuation`
210 |
212 |
220 |
213 |
218 |
214 |
217 | `Other`
219 |
221 |
229 |
222 |
227 |
223 |
226 | `Other_Letter`
228 |
230 |
238 |
231 |
236 |
232 |
235 | `Other_Number`
237 |
239 |
247 |
240 |
245 |
241 |
244 | `Other_Punctuation`
246 |
248 |
256 |
249 |
254 |
250 |
253 | `Other_Symbol`
255 |
257 |
265 |
258 |
263 |
259 |
262 | `Paragraph_Separator`
264 |
266 |
274 |
267 |
272 |
268 |
271 | `Private_Use`
273 |
275 |
284 |
276 |
282 |
277 |
281 | `Punctuation`
283 |
285 |
293 |
286 |
291 |
287 |
290 | `Separator`
292 |
294 |
302 |
295 |
300 |
296 |
299 | `Space_Separator`
301 |
303 |
311 |
304 |
309 |
305 |
308 | `Spacing_Mark`
310 |
312 |
320 |
313 |
318 |
314 |
317 | `Surrogate`
319 |
321 |
329 |
322 |
327 |
323 |
326 | `Symbol`
328 |
330 |
338 |
331 |
336 |
332 |
335 | `Titlecase_Letter`
337 |
339 |
347 |
340 |
345 |
341 |
344 | `Unassigned`
346 |
348 |
356 |
349 |
354 |
350 |
353 | `Uppercase_Letter`
355 |
4 |
5 |
419 |
6 |
9 |
10 | Property name and aliases
7 | Canonical property name
8 |
11 |
14 | `ASCII`
12 | `ASCII`
13 |
15 |
23 |
16 |
21 |
17 |
20 | `ASCII_Hex_Digit`
22 |
24 |
32 |
25 |
30 |
26 |
29 | `Alphabetic`
31 |
33 |
36 | `Any`
34 | `Any`
35 |
37 |
40 | `Assigned`
38 | `Assigned`
39 |
41 |
49 |
42 |
47 |
43 |
46 | `Bidi_Control`
48 |
50 |
58 |
51 |
56 |
52 |
55 | `Bidi_Mirrored`
57 |
59 |
67 |
60 |
65 |
61 |
64 | `Case_Ignorable`
66 |
68 |
71 | `Cased`
69 | `Cased`
70 |
72 |
80 |
73 |
78 |
74 |
77 | `Changes_When_Casefolded`
79 |
81 |
89 |
82 |
87 |
83 |
86 | `Changes_When_Casemapped`
88 |
90 |
98 |
91 |
96 |
92 |
95 | `Changes_When_Lowercased`
97 |
99 |
107 |
100 |
105 |
101 |
104 | `Changes_When_NFKC_Casefolded`
106 |
108 |
116 |
109 |
114 |
110 |
113 | `Changes_When_Titlecased`
115 |
117 |
125 |
118 |
123 |
119 |
122 | `Changes_When_Uppercased`
124 |
126 |
129 | `Dash`
127 | `Dash`
128 |
130 |
138 |
131 |
136 |
132 |
135 | `Default_Ignorable_Code_Point`
137 |
139 |
147 |
140 |
145 |
141 |
144 | `Deprecated`
146 |
148 |
156 |
149 |
154 |
150 |
153 | `Diacritic`
155 |
157 |
160 | `Emoji`
158 | `Emoji`
159 |
161 |
164 | `Emoji_Component`
162 | `Emoji_Component`
163 |
165 |
168 | `Emoji_Modifier`
166 | `Emoji_Modifier`
167 |
169 |
172 | `Emoji_Modifier_Base`
170 | `Emoji_Modifier_Base`
171 |
173 |
176 | `Emoji_Presentation`
174 | `Emoji_Presentation`
175 |
177 |
185 |
178 |
183 |
179 |
182 | `Extender`
184 |
186 |
194 |
187 |
192 |
188 |
191 | `Grapheme_Base`
193 |
195 |
203 |
196 |
201 |
197 |
200 | `Grapheme_Extend`
202 |
204 |
212 |
205 |
210 |
206 |
209 | `Hex_Digit`
211 |
213 |
221 |
214 |
219 |
215 |
218 | `IDS_Binary_Operator`
220 |
222 |
230 |
223 |
228 |
224 |
227 | `IDS_Trinary_Operator`
229 |
231 |
239 |
232 |
237 |
233 |
236 | `ID_Continue`
238 |
240 |
248 |
241 |
246 |
242 |
245 | `ID_Start`
247 |
249 |
257 |
250 |
255 |
251 |
254 | `Ideographic`
256 |
258 |
266 |
259 |
264 |
260 |
263 | `Join_Control`
265 |
267 |
275 |
268 |
273 |
269 |
272 | `Logical_Order_Exception`
274 |
276 |
284 |
277 |
282 |
278 |
281 | `Lowercase`
283 |
285 |
288 | `Math`
286 | `Math`
287 |
289 |
297 |
290 |
295 |
291 |
294 | `Noncharacter_Code_Point`
296 |
298 |
306 |
299 |
304 |
300 |
303 | `Pattern_Syntax`
305 |
307 |
315 |
308 |
313 |
309 |
312 | `Pattern_White_Space`
314 |
316 |
324 |
317 |
322 |
318 |
321 | `Quotation_Mark`
323 |
325 |
328 | `Radical`
326 | `Radical`
327 |
329 |
337 |
330 |
335 |
331 |
334 | `Regional_Indicator`
336 |
338 |
346 |
339 |
344 |
340 |
343 | `Sentence_Terminal`
345 |
347 |
355 |
348 |
353 |
349 |
352 | `Soft_Dotted`
354 |
356 |
364 |
357 |
362 |
358 |
361 | `Terminal_Punctuation`
363 |
365 |
373 |
366 |
371 |
367 |
370 | `Unified_Ideograph`
372 |
374 |
382 |
375 |
380 |
376 |
379 | `Uppercase`
381 |
383 |
391 |
384 |
389 |
385 |
388 | `Variation_Selector`
390 |
392 |
400 |
393 |
398 |
394 |
397 | `White_Space`
399 |
401 |
409 |
402 |
407 |
403 |
406 | `XID_Continue`
408 |
410 |
418 |
411 |
416 |
412 |
415 | `XID_Start`
417 |
4 | title: Unicode property escapes in regular expressions 5 | status: proposal 6 | stage: 4 7 | location: https://tc39.github.io/proposal-regexp-unicode-property-escapes/ 8 | copyright: false 9 | contributors: Mathias Bynens 10 |11 | 12 | 13 | 34 | 35 |
The syntax listed in 21.2.1 Patterns is modified as follows.
36 | 37 |The following items are appended to 21.2.1.1 Static Semantics: Early Errors.
101 | 102 |The following two abstract operations are appended to 21.2.2.8 Atom.
122 | 123 |The algorithm uses values from the following tables, which associate supported Unicode property names and property aliases and their canonical property names.
126 |Implementations must support the following non-binary Unicode properties and their property aliases:
127 |Additionally, implementations must support the following binary Unicode properties and their property aliases:
129 |The abstract operation UnicodeMatchProperty takes a parameter _p_ that is a List of Unicode code points and performs the following steps:
131 |To ensure interoperability, implementations must not extend Unicode property support to the remaining properties.
137 |Implementations must only recognize the property aliases listed in
Implementations must only recognize the property value aliases and canonical property value names listed in
For example, `Script_Extensions` (property name) and `scx` (property alias) are valid, but `script_extensions` or `Scx` aren’t.
141 |The listed properties form a superset of what UTS18 RL1.2 requires.
144 |The algorithm uses values from the following tables, which associate canonical Unicode property names and their supported values and value aliases:
150 |The abstract operation UnicodeMatchPropertyValue takes two parameters _p_ and _v_, each of which is a List of Unicode code points, and performs the following steps:
153 |Only the canonical property values and property value aliases listed in
For example, `Xpeo` and `Old_Persian` are valid `Script_Extension` values, but `xpeo` and `Old Persian` aren’t.
162 |This algorithm differs from the matching rules for symbolic values listed in UAX44: case,
The following is appended to the list of productions in 21.2.2.12 CharacterClassEscape.
171 | 172 |The production
The production
The production
The production
The following is appended to the bibliography.
191 | 192 | 193 |\p{UnicodePropertyName=UnicodePropertyValue}
59 |
60 | The aliases defined in [`PropertyAliases.txt`](http://unicode.org/Public/UNIDATA/PropertyAliases.txt) and [`PropertyValueAliases.txt`](http://unicode.org/Public/UNIDATA/PropertyValueAliases.txt) may be used instead of the canonical property and value names. The use of an unknown property name or value triggers an early `SyntaxError`.
61 |
62 | For binary properties, the following syntax is available:
63 |
64 | \p{LoneUnicodePropertyNameOrValue}
65 |
66 | This syntax may also be used as a shorthand for `General_Category` values, e.g. `\p{Letter}` instead of `\p{General_Category=Letter}`.
67 |
68 | `\P{…}` is the negated form of `\p{…}`.
69 |
70 | Implementations must support the list of Unicode properties and their property aliases mentioned in the spec proposal. This includes `General_Category`, `Script`, `Script_Extensions`, and some binary properties (including but not limited to `Alphabetic`, `Uppercase`, `Lowercase`, `White_Space`, `Noncharacter_Code_Point`, `Default_Ignorable_Code_Point`, `Any`, `ASCII`, `Assigned`, `ID_Start`, `ID_Continue`, `Join_Control`, `Emoji_Presentation`, `Emoji_Modifier`, `Emoji_Modifier_Base`, etc.). This is a superset of what [UTS18 RL1.2](http://unicode.org/reports/tr18/#RL1.2) requires. To ensure interoperability, implementations must not extend Unicode property support to the remaining properties.
71 |
72 | ### FAQ
73 |
74 | #### What about backwards compatibility?
75 |
76 | In regular expressions without the `u` flag, the pattern `\p` is an (unnecessary) escape sequence for `p`. Patterns of the form `\p{Letter}` might already be present in existing regular expressions without the `u` flag, and therefore we cannot assign new meaning to such patterns without breaking backwards compatibility.
77 |
78 | For this reason, ECMAScript 2015 made unnecessary escape sequences like `\p` and `\P` [throw an exception](https://bugs.ecmascript.org/show_bug.cgi?id=3157) when the `u` flag is set. This enables us to change the meaning of `\p{…}` and `\P{…}` in regular expressions with the `u` flag without breaking backwards compatibility.
79 |
80 | #### Why not support loose matching?
81 |
82 | [UAX44-LM3](http://unicode.org/reports/tr44/#Matching_Symbolic) specifies the loose matching rules for comparing Unicode property and value aliases.
83 |
84 | > Ignore case, whitespace, underscores, hyphens, […]
85 |
86 | Loose matching makes `\p{lB=Ba}` equivalent to `\p{Line_Break=Break_After}` or `/\p{___lower C-A-S-E___}/u` equivalent to `/\p{Lowercase}/u`. We assert that this feature does not add any value, and in fact harms code readability and maintainability.
87 |
88 | Should the need arise, then support for loose matching can always be added later, as part of a separate ECMAScript proposal. If we add it now, however, there is no going back.
89 |
90 | #### Why not support the `is` prefix?
91 |
92 | [UAX44-LM3](http://unicode.org/reports/tr44/#Matching_Symbolic) specifies the loose matching rules for comparing Unicode property and value aliases, one of which is:
93 |
94 | > Ignore […] any initial prefix string `is`.
95 |
96 | This rule makes `Script=IsGreek` and `IsScript=Greek` equivalent to `Script=Greek`. We assert that this feature does not add any value, and in fact harms code readability. It introduces ambiguity and increases implementation complexity, since some property values or aliases already start with `is`, e.g. `Decomposition_Type=Isolated` and `Line_Break=IS` which is an alias for `Line_Break=Infix_Numeric`.
97 |
98 | Compatibility with Unicode property escapes in other languages is not an argument either, since [no existing regular expression engine](http://unicode.org/mail-arch/unicode-ml/y2016-m06/0012.html) seems to implement the `is` prefix exactly as described in UAX44-LM3, and those that partially implement it wildly differ in behavior.
99 |
100 | Strictness is preferred over ambiguity.
101 |
102 | Should the need arise, then support for the `is` prefix can always be added later, as part of a separate ECMAScript proposal. If we add it now, however, there is no going back.
103 |
104 | #### Why not support e.g. `\pL` as a shorthand for `\p{L}`?
105 |
106 | This shorthand doesn’t add any value and as such the added implementation complexity (small as it may be) isn’t worth it. `\p{L}` works; there’s no reason to introduce another syntax for it other than compatibility with other languages which is an utopian goal anyhow.
107 |
108 | Should the need arise, then support for this shorthand can always be added later, as part of a separate ECMAScript proposal. If we add it now, however, there is no going back.
109 |
110 | #### Why use `=` (and not something else) as a separator?
111 |
112 | The `=` in `\p{…=…}` aligns with the `=` in `(?=…)` for positive lookaheads and `(?<=…)` for positive lookbehinds. Also, `=` is what most regular expression engines use as a separator. [See issue #8 for more information.](https://github.com/tc39/proposal-regexp-unicode-property-escapes/issues/8)
113 |
114 | #### Why not support `:` as a separator in addition to `=`?
115 |
116 | Supporting multiple separators doesn’t add any value and as such the added implementation complexity (small as it may be) isn’t worth it. `\p{Script_Extensions=Greek}` works; there’s no reason to introduce another syntax for it other than compatibility with other languages which is an utopian goal anyhow.
117 |
118 | Should the need arise, then support for the `:` separator can always be added later, as part of a separate ECMAScript proposal. If we add it now, however, there is no going back.
119 |
120 | #### Why not support e.g. `\p{ScriptName}` as a shorthand for `\p{Script=ScriptName}`?
121 |
122 | In the majority of use cases, `Script_Extensions` should be used over `Script`. [UTS24](http://unicode.org/reports/tr24/#Multiple_Script_Values) explains this nicely with practical examples. As such, it would make more sense to add a shorthand for `Script_Extensions` than for `Script`. Doing either would cause confusion, however, since the sets of values for these two properties are identical. For example, it wouldn’t be clear if `\p{Old_Persian}` refers to the `Script` or `Script_Extensions` with that name.
123 |
124 | #### Why not overload `\u{…}` instead of adding `\p{…}` and `\P{…}`?
125 |
126 | The main argument in favor of overloading `\u{…}` is that it hints that it is Unicode. We assert that this hint is unnecessary, as the required `u` flag on the regular expression already indicates Unicode.
127 |
128 | The `p` in `\p{…}` stands for “property”. Combined with the `u` flag, this indicates nicely that the expression within the braces relates to a Unicode property.
129 |
130 | Overloading `\u{…}` introduces an ambiguity. Imagine a new binary property or general category named `Beef` is added to the Unicode Standard. Since `Beef` consists of hexadecimal digits only (`[A-Fa-f0-9]`), it’s unclear whether `\u{Beef}` is a code point escape sequence for [U+BEEF HANGUL SYLLABLE BBEGS](https://codepoints.net/U+BEEF) or whether it’s a property escape sequence referring to the property/category named `Beef`.
131 |
132 | Existing other languages with support for Unicode property escapes use `\p{…}` and `\P{…}`. Although compatibility with these other implementations is a non-goal (since they’re not compatible amongst themselves to begin with), it makes sense to follow the tradition here and re-use the base syntax that developers are already familiar with.
133 |
134 | #### Why not support the `Name` property (`\p{Name=…}`)?
135 |
136 | Developers already have a way to refer to a specific symbol without having to use that symbol in their source code: Unicode code point escapes of the form `\u{1D306}`. As such, the need to support `\p{Name=TETRAGRAM FOR CENTRE}` is not strong enough to warrant inclusion in this proposal.
137 |
138 | Support for the `Name` property can always be added later, as part of a separate ECMAScript proposal. If we add it now, however, there is no going back.
139 |
140 | ## Illustrative examples
141 |
142 | ### Unicode-aware version of `\d`
143 |
144 | To match any decimal number in Unicode rather than just ASCII `[0-9]`, use `\p{Decimal_Number}` instead of `\d` as per [UTS18](http://unicode.org/reports/tr18/#digit).
145 |
146 | ```js
147 | const regex = /^\p{Decimal_Number}+$/u;
148 | regex.test('𝟏𝟐𝟑𝟜𝟝𝟞𝟩𝟪𝟫𝟬𝟭𝟮𝟯𝟺𝟻𝟼');
149 | // → true
150 | ```
151 |
152 | ### Unicode-aware version of `\D`
153 |
154 | To match any Unicode symbol that is not a decimal number rather than just `[^0-9]`, use `\P{Decimal_Number}` instead of `\D`.
155 |
156 | ```js
157 | const regex = /^\P{Decimal_Number}+$/u;
158 | regex.test('Իմ օդաթիռը լի է օձաձկերով');
159 | // → true
160 | ```
161 |
162 | ### Unicode-aware version of `\w`
163 |
164 | To match any word symbol in Unicode rather than just ASCII `[a-zA-Z0-9_]`, use `[\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}]` as per [UTS18](http://unicode.org/reports/tr18/#word).
165 |
166 | ```js
167 | const regex = /([\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}]+)/gu;
168 | const text = `
169 | Amharic: የኔ ማንዣበቢያ መኪና በዓሣዎች ተሞልቷል
170 | Bengali: আমার হভারক্রাফ্ট কুঁচে মাছ-এ ভরা হয়ে গেছে
171 | Georgian: ჩემი ხომალდი საჰაერო ბალიშზე სავსეა გველთევზებით
172 | Macedonian: Моето летачко возило е полно со јагули
173 | Vietnamese: Tàu cánh ngầm của tôi đầy lươn
174 | `;
175 |
176 | let match;
177 | while (match = regex.exec(text)) {
178 | const word = match[1];
179 | console.log(`Matched word with length ${ word.length }: ${ word }`);
180 | }
181 | ```
182 |
183 | Console output:
184 |
185 | ```
186 | Matched word with length 7: Amharic
187 | Matched word with length 2: የኔ
188 | Matched word with length 6: ማንዣበቢያ
189 | Matched word with length 3: መኪና
190 | Matched word with length 5: በዓሣዎች
191 | Matched word with length 5: ተሞልቷል
192 | Matched word with length 7: Bengali
193 | Matched word with length 4: আমার
194 | Matched word with length 11: হভারক্রাফ্ট
195 | Matched word with length 5: কুঁচে
196 | Matched word with length 3: মাছ
197 | Matched word with length 1: এ
198 | Matched word with length 3: ভরা
199 | Matched word with length 3: হয়ে
200 | Matched word with length 4: গেছে
201 | Matched word with length 8: Georgian
202 | Matched word with length 4: ჩემი
203 | Matched word with length 7: ხომალდი
204 | Matched word with length 7: საჰაერო
205 | Matched word with length 7: ბალიშზე
206 | Matched word with length 6: სავსეა
207 | Matched word with length 12: გველთევზებით
208 | Matched word with length 10: Macedonian
209 | Matched word with length 5: Моето
210 | Matched word with length 7: летачко
211 | Matched word with length 6: возило
212 | Matched word with length 1: е
213 | Matched word with length 5: полно
214 | Matched word with length 2: со
215 | Matched word with length 6: јагули
216 | Matched word with length 10: Vietnamese
217 | Matched word with length 3: Tàu
218 | Matched word with length 4: cánh
219 | Matched word with length 4: ngầm
220 | Matched word with length 3: của
221 | Matched word with length 3: tôi
222 | Matched word with length 3: đầy
223 | Matched word with length 4: lươn
224 | ```
225 |
226 | ### Unicode-aware version of `\W`
227 |
228 | To match any non-word symbol in Unicode rather than just `[^a-zA-Z0-9_]`, use `[^\p{Alphabetic}\p{Mark}\p{Decimal_Number}\p{Connector_Punctuation}\p{Join_Control}]`.
229 |
230 | ### Matching emoji
231 |
232 | To match emoji symbols, the binary properties from [UTR51](http://unicode.org/reports/tr51/) come in handy.
233 |
234 | ```js
235 | const regex = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu;
236 | ```
237 |
238 | This regular expression matches, from left to right:
239 |
240 | 1. emoji with optional modifiers (`\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?`);
241 | 2. any remaining symbols that render as emoji rather than text by default (`\p{Emoji_Presentation}`);
242 | 3. symbols that render as text by default, but are forced to render as emoji using U+FE0F VARIATION SELECTOR-16 (`\p{Emoji}\uFE0F`).
243 |
244 | ```js
245 | const regex = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu;
246 | const text = `
247 | \u{231A}: ⌚ default emoji presentation character (Emoji_Presentation)
248 | \u{2194}\u{FE0F}: ↔️ default text presentation character rendered as emoji
249 | \u{1F469}: 👩 emoji modifier base (Emoji_Modifier_Base)
250 | \u{1F469}\u{1F3FF}: 👩🏿 emoji modifier base followed by a modifier
251 | `;
252 |
253 | let match;
254 | while (match = regex.exec(text)) {
255 | const emoji = match[0];
256 | console.log(`Matched sequence ${ emoji } — code points: ${ [...emoji].length }`);
257 | }
258 | ```
259 |
260 | Console output:
261 |
262 | ```
263 | Matched sequence ⌚ — code points: 1
264 | Matched sequence ⌚ — code points: 1
265 | Matched sequence ↔️ — code points: 2
266 | Matched sequence ↔️ — code points: 2
267 | Matched sequence 👩 — code points: 1
268 | Matched sequence 👩 — code points: 1
269 | Matched sequence 👩🏿 — code points: 2
270 | Matched sequence 👩🏿 — code points: 2
271 | ```
272 |
273 | ### Other examples
274 |
275 | Match any numeric symbol in Unicode, including non-decimal symbols such as Roman numerals:
276 |
277 | ```js
278 | const regex = /^\p{Number}+$/u;
279 | regex.test('²³¹¼½¾𝟏𝟐𝟑𝟜𝟝𝟞𝟩𝟪𝟫𝟬𝟭𝟮𝟯𝟺𝟻𝟼㉛㉜㉝ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅺⅻⅼⅽⅾⅿ');
280 | // → true
281 | ```
282 |
283 | Match ECMAScript [`IdentifierStart`](https://tc39.github.io/ecma262/#prod-IdentifierStart) or [`IdentifierPart`](https://tc39.github.io/ecma262/#prod-IdentifierPart) symbols [without the need for complex regular expressions generated by build scripts](https://gist.github.com/mathiasbynens/6334847):
284 |
285 | ```js
286 | const regexIdentifierStart = /[$_\p{ID_Start}]/u;
287 | const regexIdentifierPart = /[$\u200C\u200D\p{ID_Continue}]/u;
288 | const regexIdentifierName = /^(?:[$_\p{ID_Start}])(?:[$\u200C\u200D\p{ID_Continue}])*$/u;
289 | ```
290 |
291 | ## Specification
292 |
293 | * [Ecmarkup source](https://github.com/tc39/proposal-regexp-unicode-property-escapes/blob/master/spec.html)
294 | * [HTML version](https://tc39.github.io/proposal-regexp-unicode-property-escapes/)
295 |
296 | ## Implementations
297 |
298 | * [V8](https://bugs.chromium.org/p/v8/issues/detail?id=4743), shipping in Chrome 64
299 | * [Safari/JavaScriptCore](https://developer.apple.com/safari/technology-preview/release-notes/) beginning in Safari Technology Preview 42
300 | * [regexpu (transpiler)](https://github.com/mathiasbynens/regexpu) with the `{ unicodePropertyEscape: true }` option enabled
301 | * [online demo](https://mothereff.in/regexpu#input=/%5Cp%7BLetter%7D/u&unicodePropertyEscape=1)
302 | * [exhaustive list of supported properties](https://github.com/mathiasbynens/regexpu-core/blob/master/property-escapes.md)
303 | * [Babel plugin](https://github.com/mathiasbynens/babel-plugin-transform-unicode-property-regex)
304 |
--------------------------------------------------------------------------------
/table-unicode-script-values.html:
--------------------------------------------------------------------------------
1 | | Property value and aliases | 7 |Canonical property value | 8 |
|---|---|
12 |
|
17 | `Adlam` | 18 |
21 |
|
26 | `Ahom` | 27 |
30 |
|
35 | `Anatolian_Hieroglyphs` | 36 |
39 |
|
44 | `Arabic` | 45 |
48 |
|
53 | `Armenian` | 54 |
57 |
|
62 | `Avestan` | 63 |
66 |
|
71 | `Balinese` | 72 |
75 |
|
80 | `Bamum` | 81 |
84 |
|
89 | `Bassa_Vah` | 90 |
93 |
|
98 | `Batak` | 99 |
102 |
|
107 | `Bengali` | 108 |
111 |
|
116 | `Bhaiksuki` | 117 |
120 |
|
125 | `Bopomofo` | 126 |
129 |
|
134 | `Brahmi` | 135 |
138 |
|
143 | `Braille` | 144 |
147 |
|
152 | `Buginese` | 153 |
156 |
|
161 | `Buhid` | 162 |
165 |
|
170 | `Canadian_Aboriginal` | 171 |
174 |
|
179 | `Carian` | 180 |
183 |
|
188 | `Caucasian_Albanian` | 189 |
192 |
|
197 | `Chakma` | 198 |
201 |
|
206 | `Cham` | 207 |
210 |
|
215 | `Cherokee` | 216 |
219 |
|
224 | `Common` | 225 |
228 |
|
234 | `Coptic` | 235 |
238 |
|
243 | `Cuneiform` | 244 |
247 |
|
252 | `Cypriot` | 253 |
256 |
|
261 | `Cyrillic` | 262 |
265 |
|
270 | `Deseret` | 271 |
274 |
|
279 | `Devanagari` | 280 |
283 |
|
288 | `Duployan` | 289 |
292 |
|
297 | `Egyptian_Hieroglyphs` | 298 |
301 |
|
306 | `Elbasan` | 307 |
310 |
|
315 | `Ethiopic` | 316 |
319 |
|
324 | `Georgian` | 325 |
328 |
|
333 | `Glagolitic` | 334 |
337 |
|
342 | `Gothic` | 343 |
346 |
|
351 | `Grantha` | 352 |
355 |
|
360 | `Greek` | 361 |
364 |
|
369 | `Gujarati` | 370 |
373 |
|
378 | `Gurmukhi` | 379 |
382 |
|
387 | `Han` | 388 |
391 |
|
396 | `Hangul` | 397 |
400 |
|
405 | `Hanunoo` | 406 |
409 |
|
414 | `Hatran` | 415 |
418 |
|
423 | `Hebrew` | 424 |
427 |
|
432 | `Hiragana` | 433 |
436 |
|
441 | `Imperial_Aramaic` | 442 |
445 |
|
451 | `Inherited` | 452 |
455 |
|
460 | `Inscriptional_Pahlavi` | 461 |
464 |
|
469 | `Inscriptional_Parthian` | 470 |
473 |
|
478 | `Javanese` | 479 |
482 |
|
487 | `Kaithi` | 488 |
491 |
|
496 | `Kannada` | 497 |
500 |
|
505 | `Katakana` | 506 |
509 |
|
514 | `Kayah_Li` | 515 |
518 |
|
523 | `Kharoshthi` | 524 |
527 |
|
532 | `Khmer` | 533 |
536 |
|
541 | `Khojki` | 542 |
545 |
|
550 | `Khudawadi` | 551 |
554 |
|
559 | `Lao` | 560 |
563 |
|
568 | `Latin` | 569 |
572 |
|
577 | `Lepcha` | 578 |
581 |
|
586 | `Limbu` | 587 |
590 |
|
595 | `Linear_A` | 596 |
599 |
|
604 | `Linear_B` | 605 |
608 |
|
613 | `Lisu` | 614 |
617 |
|
622 | `Lycian` | 623 |
626 |
|
631 | `Lydian` | 632 |
635 |
|
640 | `Mahajani` | 641 |
644 |
|
649 | `Malayalam` | 650 |
653 |
|
658 | `Mandaic` | 659 |
662 |
|
667 | `Manichaean` | 668 |
671 |
|
676 | `Marchen` | 677 |
680 |
|
685 | `Masaram_Gondi` | 686 |
689 |
|
694 | `Meetei_Mayek` | 695 |
698 |
|
703 | `Mende_Kikakui` | 704 |
707 |
|
712 | `Meroitic_Cursive` | 713 |
716 |
|
721 | `Meroitic_Hieroglyphs` | 722 |
725 |
|
730 | `Miao` | 731 |
734 |
|
739 | `Modi` | 740 |
743 |
|
748 | `Mongolian` | 749 |
752 |
|
757 | `Mro` | 758 |
761 |
|
766 | `Multani` | 767 |
770 |
|
775 | `Myanmar` | 776 |
779 |
|
784 | `Nabataean` | 785 |
788 |
|
793 | `New_Tai_Lue` | 794 |
797 |
|
802 | `Newa` | 803 |
806 |
|
811 | `Nko` | 812 |
815 |
|
820 | `Nushu` | 821 |
824 |
|
829 | `Ogham` | 830 |
833 |
|
838 | `Ol_Chiki` | 839 |
842 |
|
847 | `Old_Hungarian` | 848 |
851 |
|
856 | `Old_Italic` | 857 |
860 |
|
865 | `Old_North_Arabian` | 866 |
869 |
|
874 | `Old_Permic` | 875 |
878 |
|
883 | `Old_Persian` | 884 |
887 |
|
892 | `Old_South_Arabian` | 893 |
896 |
|
901 | `Old_Turkic` | 902 |
905 |
|
910 | `Oriya` | 911 |
914 |
|
919 | `Osage` | 920 |
923 |
|
928 | `Osmanya` | 929 |
932 |
|
937 | `Pahawh_Hmong` | 938 |
941 |
|
946 | `Palmyrene` | 947 |
950 |
|
955 | `Pau_Cin_Hau` | 956 |
959 |
|
964 | `Phags_Pa` | 965 |
968 |
|
973 | `Phoenician` | 974 |
977 |
|
982 | `Psalter_Pahlavi` | 983 |
986 |
|
991 | `Rejang` | 992 |
995 |
|
1000 | `Runic` | 1001 |
1004 |
|
1009 | `Samaritan` | 1010 |
1013 |
|
1018 | `Saurashtra` | 1019 |
1022 |
|
1027 | `Sharada` | 1028 |
1031 |
|
1036 | `Shavian` | 1037 |
1040 |
|
1045 | `Siddham` | 1046 |
1049 |
|
1054 | `SignWriting` | 1055 |
1058 |
|
1063 | `Sinhala` | 1064 |
1067 |
|
1072 | `Sora_Sompeng` | 1073 |
1076 |
|
1081 | `Soyombo` | 1082 |
1085 |
|
1090 | `Sundanese` | 1091 |
1094 |
|
1099 | `Syloti_Nagri` | 1100 |
1103 |
|
1108 | `Syriac` | 1109 |
1112 |
|
1117 | `Tagalog` | 1118 |
1121 |
|
1126 | `Tagbanwa` | 1127 |
1130 |
|
1135 | `Tai_Le` | 1136 |
1139 |
|
1144 | `Tai_Tham` | 1145 |
1148 |
|
1153 | `Tai_Viet` | 1154 |
1157 |
|
1162 | `Takri` | 1163 |
1166 |
|
1171 | `Tamil` | 1172 |
1175 |
|
1180 | `Tangut` | 1181 |
1184 |
|
1189 | `Telugu` | 1190 |
1193 |
|
1198 | `Thaana` | 1199 |
1202 |
|
1207 | `Thai` | 1208 |
1211 |
|
1216 | `Tibetan` | 1217 |
1220 |
|
1225 | `Tifinagh` | 1226 |
1229 |
|
1234 | `Tirhuta` | 1235 |
1238 |
|
1243 | `Ugaritic` | 1244 |
1247 |
|
1252 | `Vai` | 1253 |
1256 |
|
1261 | `Warang_Citi` | 1262 |
1265 |
|
1270 | `Yi` | 1271 |
1274 |
|
1279 | `Zanabazar_Square` | 1280 |