# XRegExp's own README points you at a different library, and version 5 moved named capture

> An MIT-licensed extended regular expression engine for JavaScript that compiles down to native RegExp objects. The author labels it a spiritual ancestor of a newer project, the named-capture breaking change in version 5 can be switched off with one call, and astral mode silently disables Unicode property escapes inside character classes.

**slevithan/xregexp** — GitHub describes it as Extended JavaScript regular expressions. The repository metadata lists JavaScript as its primary language. The metadata lists the MIT license. This article stays within the project description and details documented in the GitHub repository README.

- Repository: https://github.com/slevithan/xregexp
- Website: http://xregexp.com/
- Stars: 3,328 · Forks: 274
- Language: JavaScript
- License: MIT
- Published: 2026-08-13 · Updated: 2026-08-18 · Language: en
- Canonical page: https://hysenlabs.com/projects/slevithan-xregexp

## The README points readers at a different library

The first thing the documentation says is that XRegExp was indispensable for heavy regex users in its time, but many of its best features have since been adopted into modern JavaScript, and it names a lighter successor project to use instead. That framing changes how to read everything else. Named capture, Unicode properties, scripts and categories, the s flag and sticky matching are all listed as features that new language standards absorbed, which means the value of this library is no longer the syntax but the reach. The line the documentation offers for that is that using XRegExp can be a way to extend those features into older browsers. The current release is 5.1.3, published on the same day as the most recent push, after a gap of about nineteen months since 5.1.2.

## Named capture moved to groups and a feature can be uninstalled

Version 5 made one breaking change: named backreference properties appear on the result's groups object, following ES2018, rather than directly on the result. The common rewrite is one line, and the documentation shows both halves:

```js
// Change this
const name = XRegExp.exec(str, regexWithNamedCapture).name;

// To this
const name = XRegExp.exec(str, regexWithNamedCapture).groups.name;
```

The more interesting part is the escape hatch. That behaviour is installed as a named feature, so a single call turns it back off after importing the library, and the same mechanism exists in the opposite direction on 4.1.0 and later, which lets you opt into the new behaviour without upgrading to version 5 at all. The mechanism is the reason XRegExp can be called extensible: syntax and methods are added through the same install and uninstall pair that resolves this one break.

## Astral mode disables property escapes inside character classes

Property escapes work on the Basic Multilingual Plane by default, up to U+FFFF. Flag A opts a pattern into full 21-bit coverage, up to U+10FFFF, which is called astral mode, and in that mode a property escape always matches a whole code point rather than a code unit. Running install for the astral feature adds the flag to every new pattern. The cost is stated in one sentence and is easy to trip over: opting in disables property escapes inside character classes, so a class has to be rewritten as an alternation with grouping, for example a group matching a property or a literal range, rather than a class containing both. Any pattern you already had written as a class will need rewriting the moment you add the flag, which makes it a decision to make once and keep, not something to toggle while debugging.

## Unicode 14 in the engine, Unicode transforms in the build

The engine documents itself as using Unicode 14.0.0, and the build dependencies match that. The Unicode data package for 14.0.0 is a devDependency, and three scripts under tools/scripts generate the category, property and script regexes that the Unicode addon consumes, writing them into the published output directory. Alongside that sits a Babel plugin for transforming Unicode property regexes, which is a convenient thing to see in a dependency list: it is the same capability, implemented as a source transform for consumers who would rather compile it than ship this library. Two more of the build plugins exist for adding CommonJS exports and for array includes, which tells you the supported floor is old enough to need both. The addon for Unicode has to be loaded deliberately when you are not using the bundled build.

## One runtime dependency, and packaging runs the tests

The dependencies field holds exactly one entry, the Babel runtime for core-js 3, and everything else is a devDependency. Consumers therefore do not inherit the build chain, which is the right shape for a library that compiles to native RegExp objects. The scripts are arranged so that no artifact exists without a check behind it. The Unicode data generation runs three node scripts, lint runs first as part of prebuild, Babel compiles src into lib, and the bundle step pipes browserify output through the standalone flag into xregexp-all.js. Tests run after a build, and the test script invokes jasmine with a configuration path, while prepack runs the tests again, so publishing cannot skip them. The package manager is pinned to a pnpm version and a lockfile and workspace file are both committed.

## main and module point at different files

Three entry declarations disagree in a way that changes what you get. Both main and browser point at lib/index.js, the Babel output, while module points at src/index.js, the untranspiled source. A bundler that honours the module field therefore consumes source that has not been through preset-env, and a CommonJS consumer gets the compiled build. That split is a deliberate trade rather than an oversight, since it lets modern bundlers skip the transform, but it means a syntax error in a file only the module path reaches will not reproduce for anyone installing from the registry through require. The published file list includes src, lib, the generated tools output, the standalone bundle and a hand-written declaration file, with the declaration supplied as types/index.d.ts rather than generated from source.

## build renumbers backreferences and strips anchors from subpatterns

The builder assembles a pattern from named subpatterns so a reusable piece can be written once:

```js
const time = XRegExp.build('(?x)^ {{hours}} ({{minutes}}) $', {
    hours: XRegExp.build('{{h12}} : | {{h24}}', {
        h12: /1[0-2]|0?[1-9]/,
        h24: /2[0-3]|[01][0-9]/
    }),
    minutes: /^[0-5][0-9]$/
});
```

Subpatterns can be strings or regex objects, and the token can be quantified as a single unit. Two conveniences do real work: a leading caret and a trailing unescaped dollar are stripped from a subpattern when both are present, so an independently useful anchored pattern can be embedded, and any backreference in the outer pattern or in a subpattern is renumbered automatically to keep pointing at the right group. Parenthesising the token is shorthand for a named capture. The one documented prohibition is that named subpatterns cannot be embedded inside character classes.

## The usage example stops in the middle of a statement

The usage section builds a date pattern with free-spacing and line comments, runs exec against a string, then loops over a sticky match to collect digits from angle-bracket tags. That loop ends mid-statement: the last line assigns the next start position from the match index and length, and there is no closing brace, so the sample cannot be pasted as it stands. It is the only code sample most readers copy, which makes it worth knowing before you conclude the library is broken. Elsewhere the material is more careful: the homepage field in the package metadata is still a plain http URL, the browser support statement is ES5 and later with Node or a RequireJS module as the other route, and search traffic for the three-point-two era still arrives for a version many major numbers behind.

## Conclusion

XRegExp earns its place when you have to support browsers or engines that predate the features it implements, because the syntax you write is compiled to native RegExp objects and performs like them, and backporting named capture, Unicode property escapes, the s flag or sticky matching into an old engine is exactly the job it was built for. Three things to check first. The author describes it as having been superseded and points readers at a newer library, so treat new projects as that project's problem and XRegExp as maintenance of what you already run. Named backreferences live on the groups object in version 5, and the compatibility path is one install or uninstall call, not a rewrite. And astral mode turns off property escapes inside character classes, so any pattern you write for astral input has to use alternation there instead.

## FAQ

### Does XRegExp run slower than native regular expressions?

No. XRegExp compiles to native RegExp objects, so patterns built with it perform the same as native ones. There is a small extra cost the first time a pattern is compiled.

### How do I keep the old named-capture behaviour in XRegExp 5?

Run the uninstall call for the namespacing feature right after importing XRegExp. On 4.1.0 and later the same mechanism works in the other direction, installing the new groups-based behaviour without upgrading to version 5.

### What does flag A do in XRegExp?

It turns on astral mode for one pattern, extending property escapes from the Basic Multilingual Plane to the full 21-bit range up to U+10FFFF and matching whole code points instead of code units. The astral feature can also be installed so the flag applies to every new pattern.

### How do I get every XRegExp addon at once?

Load the bundled build, xregexp-all.js, instead of assembling addons individually. Without it, the Unicode base script has to be included first, followed by the addons for the categories, properties or scripts you need.

### Does installing XRegExp add dependencies to my project?

One: the Babel runtime for core-js 3. Everything else in the package manifest is a devDependency used to generate Unicode data, compile and bundle.

## Sources

- [Official documentation](http://xregexp.com/)
- [Official README](https://github.com/slevithan/xregexp#readme)
- [Project repository](https://github.com/slevithan/xregexp)
- [Release notes](https://github.com/slevithan/xregexp/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/slevithan-xregexp
