Unicode Property Escapes Match Scripts
Match Greek script, numbers, letters, and pictographs with Unicode property escapes, including the required u flag.
Code
// Unicode property escapes match code points by category.
const greek = /\p{Script=Greek}+/gu;
const numbers = /\p{Number}+/gu;
const sample = 'Ωμέγα 42 Привет';
console.log('greek:', sample.match(greek));
console.log('numbers:', sample.match(numbers));
const letters = [...sample].filter((char) => /\p{Letter}/u.test(char));
console.log('letters:', letters.join(''));
const emoji = 'a👍🏽b';
const pictographs = [...emoji].filter((char) => /\p{Extended_Pictographic}/u.test(char));
console.log('pictographs:', pictographs.length);
const nonAscii = [...sample].filter((char) => char.codePointAt(0) > 127);
console.log('non-ascii code points:', nonAscii.length);Output
Captured from a sandboxed run of this snippet in the build pipeline.
greek: [ 'Ωμέγα' ]
numbers: [ '42' ]
letters: ΩμέγαПривет
pictographs: 1
non-ascii code points: 11How it works
Top-level bindings greek, numbers, sample, letters hold the demo state — nothing sits inside a function scope.
Applying it
The demo output is labeled (greek:, numbers:, letters:), so every printed line maps back to its originating operation.
Statements that matter
const pictographs = [...emoji].filter((char) => /\p{Extended_Pictographic}/u.test(char));
const nonAscii = [...sample].filter((char) => char.codePointAt(0) > 127);
const letters = [...sample].filter((char) => /\p{Letter}/u.test(char));
Interactive Tools for This Topic
Regular Expression TesterTest regular expressions against sample text with live match highlighting, capture group extraction, and flags support for global, case-insensitive, and multiline modes.ASCII Table ReferenceLook up any ASCII code point 0-127 by decimal, hex, or character and see the binary, octal, and control-name view.Character Frequency AnalyzerCount how often each character appears in a text, with Unicode code points, optional case folding, and whitespace exclusion.Fuzzy Match TesterTest subsequence fuzzy matching: check whether pattern characters appear in order inside a text, with positions and highlighting.
FAQ
- Which packages does this snippet need?
- None. Every symbol the code uses resolves inside the standard library. Its state lives in module-level bindings: `greek`, `numbers`, `sample`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.