{\itshape regexpu} is a source code transpiler that enables the use of ES2015 Unicode regular expressions in Java\+Script-\/of-\/today (ES5).

{\itshape regexpu-\/core} contains \+\_\+regexpu\+\_\+’s core functionality, i.\+e. {\ttfamily rewrite\+Pattern(pattern, flag)}, which enables rewriting regular expressions that make use of \href{https://mathiasbynens.be/notes/es6-unicode-regex}{\texttt{ the ES2015 {\ttfamily u} flag}} into equivalent ES5-\/compatible regular expression patterns.\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24116}{}\doxysection{Installation}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24116}
To use {\itshape regexpu-\/core} programmatically, install it as a dependency via \href{https://www.npmjs.com/}{\texttt{ npm}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install regexpu-\/core -\/-\/save }

\end{DoxyCode}


Then, {\ttfamily require} it\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{const rewritePattern = require('regexpu-\/core'); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24117}{}\doxysection{API}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24117}
This module exports a single function named {\ttfamily rewrite\+Pattern}.\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24118}{}\doxysubsection{$<$tt$>$rewrite\+Pattern(pattern, flags, options)$<$/tt$>$}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24118}
This function takes a string that represents a regular expression pattern as well as a string representing its flags, and returns an ES5-\/compatible version of the pattern.


\begin{DoxyCode}{0}
\DoxyCodeLine{rewritePattern('foo.bar', 'u');}
\DoxyCodeLine{// → 'foo(?:[\(\backslash\)\(\backslash\)0-\/\(\backslash\)\(\backslash\)t\(\backslash\)\(\backslash\)x0B\(\backslash\)\(\backslash\)f\(\backslash\)\(\backslash\)x0E-\/\(\backslash\)\(\backslash\)u2027\(\backslash\)\(\backslash\)u202A-\/\(\backslash\)\(\backslash\)uD7FF\(\backslash\)\(\backslash\)uDC00-\/\(\backslash\)\(\backslash\)uFFFF]|[\(\backslash\)\(\backslash\)uD800-\/\(\backslash\)\(\backslash\)uDBFF][\(\backslash\)\(\backslash\)uDC00-\/\(\backslash\)\(\backslash\)uDFFF]|[\(\backslash\)\(\backslash\)uD800-\/\(\backslash\)\(\backslash\)uDBFF])bar'}
\DoxyCodeLine{}
\DoxyCodeLine{rewritePattern('[\(\backslash\)\(\backslash\)u\{1D306\}-\/\(\backslash\)\(\backslash\)u\{1D308\}a-\/z]', 'u');}
\DoxyCodeLine{// → '(?:[a-\/z]|\(\backslash\)\(\backslash\)uD834[\(\backslash\)\(\backslash\)uDF06-\/\(\backslash\)\(\backslash\)uDF08])'}
\DoxyCodeLine{}
\DoxyCodeLine{rewritePattern('[\(\backslash\)\(\backslash\)u\{1D306\}-\/\(\backslash\)\(\backslash\)u\{1D308\}a-\/z]', 'ui');}
\DoxyCodeLine{// → '(?:[a-\/z\(\backslash\)\(\backslash\)u017F\(\backslash\)\(\backslash\)u212A]|\(\backslash\)\(\backslash\)uD834[\(\backslash\)\(\backslash\)uDF06-\/\(\backslash\)\(\backslash\)uDF08])' }

\end{DoxyCode}


{\itshape regexpu-\/core} can rewrite non-\/\+ES6 regular expressions too, which is useful to demonstrate how their behavior changes once the {\ttfamily u} and {\ttfamily i} flags are added\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{// In ES5, the dot operator only matches BMP symbols:}
\DoxyCodeLine{rewritePattern('foo.bar');}
\DoxyCodeLine{// → 'foo(?:[\(\backslash\)\(\backslash\)0-\/\(\backslash\)\(\backslash\)t\(\backslash\)\(\backslash\)x0B\(\backslash\)\(\backslash\)f\(\backslash\)\(\backslash\)x0E-\/\(\backslash\)\(\backslash\)u2027\(\backslash\)\(\backslash\)u202A-\/\(\backslash\)\(\backslash\)uFFFF])bar'}
\DoxyCodeLine{}
\DoxyCodeLine{// But with the ES2015 `u` flag, it matches astral symbols too:}
\DoxyCodeLine{rewritePattern('foo.bar', 'u');}
\DoxyCodeLine{// → 'foo(?:[\(\backslash\)\(\backslash\)0-\/\(\backslash\)\(\backslash\)t\(\backslash\)\(\backslash\)x0B\(\backslash\)\(\backslash\)f\(\backslash\)\(\backslash\)x0E-\/\(\backslash\)\(\backslash\)u2027\(\backslash\)\(\backslash\)u202A-\/\(\backslash\)\(\backslash\)uD7FF\(\backslash\)\(\backslash\)uDC00-\/\(\backslash\)\(\backslash\)uFFFF]|[\(\backslash\)\(\backslash\)uD800-\/\(\backslash\)\(\backslash\)uDBFF][\(\backslash\)\(\backslash\)uDC00-\/\(\backslash\)\(\backslash\)uDFFF]|[\(\backslash\)\(\backslash\)uD800-\/\(\backslash\)\(\backslash\)uDBFF])bar' }

\end{DoxyCode}


The optional {\ttfamily options} argument recognizes the following properties\+:\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24119}{}\doxysubsubsection{$<$tt$>$dot\+All\+Flag$<$/tt$>$ (default\+: $<$tt$>$false$<$/tt$>$)}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24119}
Setting this option to {\ttfamily true} enables support for \href{https://github.com/mathiasbynens/es-regexp-dotall-flag}{\texttt{ the {\ttfamily s} ({\ttfamily dot\+All}) flag}}.


\begin{DoxyCode}{0}
\DoxyCodeLine{rewritePattern('.');}
\DoxyCodeLine{// → '[\(\backslash\)\(\backslash\)0-\/\(\backslash\)\(\backslash\)t\(\backslash\)\(\backslash\)x0B\(\backslash\)\(\backslash\)f\(\backslash\)\(\backslash\)x0E-\/\(\backslash\)\(\backslash\)u2027\(\backslash\)\(\backslash\)u202A-\/\(\backslash\)\(\backslash\)uFFFF]'}
\DoxyCodeLine{}
\DoxyCodeLine{rewritePattern('.', '', \{}
\DoxyCodeLine{  'dotAllFlag': true}
\DoxyCodeLine{\});}
\DoxyCodeLine{// → '[\(\backslash\)\(\backslash\)0-\/\(\backslash\)\(\backslash\)t\(\backslash\)\(\backslash\)x0B\(\backslash\)\(\backslash\)f\(\backslash\)\(\backslash\)x0E-\/\(\backslash\)\(\backslash\)u2027\(\backslash\)\(\backslash\)u202A-\/\(\backslash\)\(\backslash\)uFFFF]'}
\DoxyCodeLine{}
\DoxyCodeLine{rewritePattern('.', 's', \{}
\DoxyCodeLine{  'dotAllFlag': true}
\DoxyCodeLine{\});}
\DoxyCodeLine{// → '[\(\backslash\)\(\backslash\)0-\/\(\backslash\)\(\backslash\)uFFFF]'}
\DoxyCodeLine{}
\DoxyCodeLine{rewritePattern('.', 'su', \{}
\DoxyCodeLine{  'dotAllFlag': true}
\DoxyCodeLine{\});}
\DoxyCodeLine{// → '(?:[\(\backslash\)\(\backslash\)0-\/\(\backslash\)\(\backslash\)uD7FF\(\backslash\)\(\backslash\)uE000-\/\(\backslash\)\(\backslash\)uFFFF]|[\(\backslash\)\(\backslash\)uD800-\/\(\backslash\)\(\backslash\)uDBFF][\(\backslash\)\(\backslash\)uDC00-\/\(\backslash\)\(\backslash\)uDFFF]|[\(\backslash\)\(\backslash\)uD800-\/\(\backslash\)\(\backslash\)uDBFF](?![\(\backslash\)\(\backslash\)uDC00-\/\(\backslash\)\(\backslash\)uDFFF])|(?:[\string^\(\backslash\)\(\backslash\)uD800-\/\(\backslash\)\(\backslash\)uDBFF]|\string^)[\(\backslash\)\(\backslash\)uDC00-\/\(\backslash\)\(\backslash\)uDFFF])' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24120}{}\doxysubsubsection{$<$tt$>$unicode\+Property\+Escape$<$/tt$>$ (default\+: $<$tt$>$false$<$/tt$>$)}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24120}
Setting this option to {\ttfamily true} enables support for Unicode property escapes\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{rewritePattern('\(\backslash\)\(\backslash\)p\{Script\_Extensions=Anatolian\_Hieroglyphs\}', 'u', \{}
\DoxyCodeLine{  'unicodePropertyEscape': true}
\DoxyCodeLine{\});}
\DoxyCodeLine{// → '(?:\(\backslash\)\(\backslash\)uD811[\(\backslash\)\(\backslash\)uDC00-\/\(\backslash\)\(\backslash\)uDE46])' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24121}{}\doxysubsubsection{$<$tt$>$lookbehind$<$/tt$>$ (default\+: $<$tt$>$false$<$/tt$>$)}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24121}
Setting this option to {\ttfamily true} enables support for \href{https://github.com/tc39/proposal-regexp-lookbehind}{\texttt{ lookbehind assertions}}.


\begin{DoxyCode}{0}
\DoxyCodeLine{rewritePattern('(?<=.)a', '', \{}
\DoxyCodeLine{  'lookbehind': true}
\DoxyCodeLine{\});}
\DoxyCodeLine{// → '(?<=[\(\backslash\)\(\backslash\)0-\/\(\backslash\)\(\backslash\)t\(\backslash\)\(\backslash\)x0B\(\backslash\)\(\backslash\)f\(\backslash\)\(\backslash\)x0E-\/\(\backslash\)\(\backslash\)u2027\(\backslash\)\(\backslash\)u202A-\/\(\backslash\)\(\backslash\)uFFFF])a' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24122}{}\doxysubsubsection{$<$tt$>$named\+Group$<$/tt$>$ (default\+: $<$tt$>$false$<$/tt$>$)}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24122}
Setting this option to {\ttfamily true} enables support for \href{https://github.com/tc39/proposal-regexp-named-groups}{\texttt{ named capture groups}}.


\begin{DoxyCode}{0}
\DoxyCodeLine{rewritePattern('(?<name>.)\(\backslash\)k<name>', '', \{}
\DoxyCodeLine{  'namedGroup': true}
\DoxyCodeLine{\});}
\DoxyCodeLine{// → '(.)\(\backslash\)1' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24123}{}\doxysubsubsection{$<$tt$>$on\+Named\+Group$<$/tt$>$}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24123}
This option is a function that gets called when a named capture group is found. It receives two parameters\+: the name of the group, and its index.


\begin{DoxyCode}{0}
\DoxyCodeLine{rewritePattern('(?<name>.)\(\backslash\)k<name>', '', \{}
\DoxyCodeLine{  'namedGroup': true,}
\DoxyCodeLine{  onNamedGroup(name, index) \{}
\DoxyCodeLine{    console.log(name, index);}
\DoxyCodeLine{    // → 'name', 1}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24124}{}\doxysubsubsection{$<$tt$>$use\+Unicode\+Flag$<$/tt$>$ (default\+: $<$tt$>$false$<$/tt$>$)}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24124}
Setting this option to {\ttfamily true} enables the use of Unicode code point escapes of the form {\ttfamily \textbackslash{}u\{…\}}. Note that in regular expressions, such escape sequences only work correctly when the ES2015 {\ttfamily u} flag is set. Enabling this setting often results in more compact output, although there are cases (such as {\ttfamily \textbackslash{}p\{Lu\}}) where it actually {\itshape increases} the output size.


\begin{DoxyCode}{0}
\DoxyCodeLine{rewritePattern('\(\backslash\)\(\backslash\)p\{Script\_Extensions=Anatolian\_Hieroglyphs\}', 'u', \{}
\DoxyCodeLine{  'unicodePropertyEscape': true,}
\DoxyCodeLine{  'useUnicodeFlag': true}
\DoxyCodeLine{\});}
\DoxyCodeLine{// → '[\(\backslash\)\(\backslash\)u\{14400\}-\/\(\backslash\)\(\backslash\)u\{14646\}]' }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24125}{}\doxysection{Author}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24125}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{1}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ \href{https://twitter.com/mathias}{\texttt{ }}    }\\\cline{1-1}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ \href{https://twitter.com/mathias}{\texttt{ }}    }\\\cline{1-1}
\endhead
\href{https://mathiasbynens.be/}{\texttt{ Mathias Bynens}}   \\\cline{1-1}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_regexpu_core_README_autotoc_md24126}{}\doxysection{License}\label{md_sfcode_node_modules_regexpu_core_README_autotoc_md24126}
{\itshape regexpu-\/core} is available under the \href{https://mths.be/mit}{\texttt{ MIT}} license. 