RegExp \p Metacharacter
Match Latin Script:
let text1 = "A";
let text2 = "Ж";
let pattern = /\p{Script=Latin}/u;
Try it Yourself »
Match a Unicode character property:
let text = "😄";
let pattern = /\p{Emoji}/v;
let result = pattern.test(text);
Try it Yourself »
Description
The \p{Unicode property} metacharacter matches characters with a Unicode character property.
Syntax
new RegExp("\\p{Unicode property}","v")
or simply:
/\p{Unicode property}/v
Note
\p and \P are only supported in Unicode-aware mode.
This means that the \u flag or the \v flag must be set.
Unicode Properties
Supported by the /u Flag
Category | Abbr | Examples |
---|---|---|
Letter | L | ABcd |
Uppercase_Letter | Lu | ABCD |
Lowercase_Letter | Ll | abcd |
Titlecase_letter | Lt | Nj (U+01CB) |
Modifier_Letter | Lm | ˆ (U+02C6) |
Other_Letter | Lo | not in Lu/Ll/Lt/Lm |
Decimal_Number | Nd | 1234 |
Letter_Number | Nl | Ⅰ Ⅳ Ⅶ |
Other_Number | No | ¼ ½ ¾ |
Math_Symbol | Sm | + = ∑ |
Currency_Symbol | Sc | $ £ € ¥ |
Other_Symbol | So | © ® |
Script | Sc | Sc=Greek |
Supported by the /v Flag
Category | Examples |
---|---|
Emoji | 😀 😁 😂 😃 |
Emoji_Presentation | |
Emoji_Modifier | 👩🏿 👩🏾 👩🏽 👩🏼 |
Emoji_Modifier_Base | |
Emoji_Component | 👩🦰 👩🦱 👩🦳 👩🦲 |
Extended_Pictographic | Used in modern Emoji sequences |
Regular Expression Methods
Regular Expression Search and Replace can be done with different methods.
These are the most common:
String Methods
Method | Description |
---|---|
match(regex) | Returns an Array of results |
matchAll(regex) | Returns an Iterator of results |
replace(regex) | Returns a new String |
replaceAll(regex) | Returns a new String |
search(regex) | Returns the index of the first match |
split(regex) | Returns an Array of results |
RegExp Methods
Method | Description |
---|---|
regex.exec() | Returns an Iterator of results |
regex.test() | Returns true or false |
Browser Support
/\p{Unicode property}/
is a JavaScript 2018 feature.
ES 2018 is supported in all modern browsers since June 2020:
Chrome 63 | Edge 79 | Firefox 78 | Safari 12 | Opera 50 |
Des 2017 | Jan 2020 | Jun 2020 | Sep 2018 | Jan 2018 |