Skip to content

Instantly share code, notes, and snippets.

Forked from jakub-g/
Created December 22, 2022 08:03
What would you like to do?
Unicode-aware JavaScript regex cheat sheet

Unicode-aware JavaScript regex (Unicode property escapes /\p{..}\P{..}/u) cheat sheet

Browser support MDN

High level intro

  • \p{...} in a regex with /u flag is a positive match
  • \P{...} in a regex with /u flag is a negative match

Unicode-aware [a-zA-Z]

'Gérard'    .match(/\p{Letter}+/gu)     // ["Gérard"]
'Łódź'      .match(/\p{Letter}+/gu)     // ["Łódź"]
'Википедия' .match(/\p{Letter}+/gu)     // ["Википедия"]

Unicode-aware \w ([a-zA-Z0-9_]+)


Unicode-aware \W (^\w)


Unicode-aware \b


\b is a word boundary for words defined like \w. AFAIU there's no short and good equivalent which works for non-ASCII. You probably want to be more specific with your regex and rely on ^, $, \s and other characters.

Matching emoji



JavaScript RegEx named capture groups

Browser support caniuse


It's possible to name the capturing group (...) via (?<name>...) syntax and later access the match via, instead of match[0], match[1] etc.

var re = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment