{"id":26183,"library":"regexpu","title":"regexpu","description":"regexpu is a source code transpiler that enables the use of ES2015 Unicode regular expressions (the `u` flag) in ES5 environments. It rewrites regex literals with the `u` flag into equivalent ES5-compatible patterns, handling Unicode properties, escapes, and case folding. Current version 4.8.0 (stable) releases infrequently; major version bumps (e.g., 2.0.0) introduced breaking changes in module export paths. Key differentiators: it is the core engine behind Babel, Traceur, and other transpilers for Unicode regex; also ships `regexpu-core` for programmatic use. Supports Node >=6 and browsers via bundlers.","status":"active","version":"4.8.0","language":"javascript","source_language":"en","source_url":"https://github.com/mathiasbynens/regexpu","tags":["javascript","codegen","desugaring","ecmascript","es5","es6","es2015","harmony"],"install":[{"cmd":"npm install regexpu","lang":"bash","label":"npm"},{"cmd":"yarn add regexpu","lang":"bash","label":"yarn"},{"cmd":"pnpm add regexpu","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Before v2.0.0, the correct import was require('regexpu').rewritePattern; after v2.0.0, ESM-style named import is preferred. CommonJS users should use the new path.","wrong":"const rewritePattern = require('regexpu').rewritePattern","symbol":"rewritePattern","correct":"import { rewritePattern } from 'regexpu'"},{"note":"Default export exists in ESM; CommonJS requires destructuring. ESM-only since v2.0.0?","wrong":"const regexpu = require('regexpu')","symbol":"default","correct":"import regexpu from 'regexpu'"},{"note":"The core module regexpu-core is the recommended way since v2.0.0; the main package now re-exports it.","wrong":"const rewritePattern = require('regexpu').rewritePattern","symbol":"rewritePattern (from regexpu-core)","correct":"import { rewritePattern } from 'regexpu-core'"}],"quickstart":{"code":"import { rewritePattern } from 'regexpu-core';\n\n// Transpile a regex with the u flag to ES5\nconst pattern = '\\\\p{ASCII_Hex_Digit}';\nconst flags = 'u';\nconst result = rewritePattern(pattern, flags);\nconsole.log(result); // '[A-Fa-f0-9]'\n\n// With support for Unicode properties\nconst pattern2 = '\\\\p{Emoji}';\nconst flags2 = 'u';\nconst result2 = rewritePattern(pattern2, flags2, { unicodePropertyEscape: true });\nconsole.log(result2); // '[...]'","lang":"typescript","description":"Transpiles a Unicode regex pattern with the u flag to an ES5-compatible equivalent, demonstrating usage of rewritePattern with options."},"warnings":[{"fix":"Update imports: use require('regexpu-core') or import { rewritePattern } from 'regexpu-core' instead of old require('regexpu').rewritePattern.","message":"Breaking change in v2.0.0: require('regexpu-core') is the new require('regexpu/rewrite-pattern')","severity":"breaking","affected_versions":">= 2.0.0"},{"fix":"Switch to require('regexpu-core') for the rewritePattern function.","message":"Using require('regexpu') directly may be deprecated; prefer regexpu-core submodule.","severity":"deprecated","affected_versions":">= 2.0.0"},{"fix":"Ensure input is a string pattern (e.g., '\\\\p{ASCII_Hex_Digit}') not '/\\\\p{ASCII_Hex_Digit}/u'.","message":"The package only transpiles the regex pattern string; it does not handle the regular expression literal syntax. Pass the pattern without delimiters.","severity":"gotcha","affected_versions":">= 1.0.0"},{"fix":"Pass options as second or third argument to rewritePattern.","message":"Options object must be passed correctly: { unicodePropertyEscape: true } to enable Unicode property escapes (default false).","severity":"gotcha","affected_versions":">= 3.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import statements: import { rewritePattern } from 'regexpu-core';","cause":"Trying to use CommonJS require in an ESM module (e.g., .mjs file or type:module).","error":"require is not defined"},{"fix":"Install the correct package: npm install regexpu --save (or regexpu-core if using core).","cause":"Module not installed or incorrect import path.","error":"Cannot find module 'regexpu' or 'regexpu-core'"},{"fix":"Use named import: import { rewritePattern } from 'regexpu-core';","cause":"Import destructuring error; default export vs named export confusion.","error":"rewritePattern is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}