# string.prototype.matchall

> Spec-compliant polyfill for String.prototype.matchAll

Latest version **4.1.0** (published 2026-08-28) · MIT license · 0 weekly downloads

> **Native alternative:** String.prototype.matchAll — Use native JavaScript (Node 12.0.0+) (https://developer.mozilla.orgGlobal_Objects/String/matchAll)

## Install

```sh
npm install string.prototype.matchall
pnpm add string.prototype.matchall
yarn add string.prototype.matchall
bun add string.prototype.matchall
```

## Health

**Score 63/100 (C)** — status: active.

Positive: has types package; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2026-08-28 |
| First published | 2017-09-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/string.prototype.matchall) |
| Module format | CommonJS |
| Node | >= 0.4 |
| Dependencies | 13 |
| Unpacked size | 57.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | ES2020, ES, String.prototype.matchAll, matchAll, match, regex, regexp, regular, expression, matches |

## Links

- npm: https://www.npmjs.com/package/string.prototype.matchall
- Repository: https://github.com/es-shims/String.prototype.matchAll
- Homepage: https://github.com/es-shims/String.prototype.matchAll#readme
- Issues: https://github.com/es-shims/String.prototype.matchAll/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/string.prototype.matchall

## Dependencies (13)

- [gopd](https://npm.io/package/gopd.md) ^1.2.0
- [call-bind](https://npm.io/package/call-bind.md) ^1.0.9
- [es-errors](https://npm.io/package/es-errors.md) ^1.3.0
- [call-bound](https://npm.io/package/call-bound.md) ^1.0.4
- [es-abstract](https://npm.io/package/es-abstract.md) ^1.24.2
- [has-symbols](https://npm.io/package/has-symbols.md) ^1.1.0
- [side-channel](https://npm.io/package/side-channel.md) ^1.1.1
- [get-intrinsic](https://npm.io/package/get-intrinsic.md) ^1.3.0
- [internal-slot](https://npm.io/package/internal-slot.md) ^1.1.0
- [es-object-atoms](https://npm.io/package/es-object-atoms.md) ^1.1.2
- [define-properties](https://npm.io/package/define-properties.md) ^1.2.1
- [set-function-name](https://npm.io/package/set-function-name.md) ^2.0.2
- [regexp.prototype.flags](https://npm.io/package/regexp.prototype.flags.md) ^1.5.4

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2026-08-28
- 4.0.12 — 2024-12-20
- 4.0.11 — 2024-03-20
- 4.0.10 — 2023-09-13
- 4.0.9 — 2023-08-29
- 4.0.8 — 2022-11-07
- 4.0.7 — 2022-03-19
- 4.0.6 — 2021-10-05
- 4.0.5 — 2021-05-25
- 4.0.4 — 2021-02-21
- 4.0.3 — 2020-11-20
- 4.0.2 — 2019-12-23
- 4.0.1 — 2019-12-13
- 4.0.0 — 2019-10-03
- 3.0.2 — 2019-10-02
- … 4 more at https://npm.io/package/string.prototype.matchall/versions

## README

# string.prototype.matchall <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

ES2020 spec-compliant shim for String.prototype.matchAll. Invoke its "shim" method to shim `String.prototype.matchAll` if it is unavailable or noncompliant.

This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment, and complies with the [spec](https://tc39.es/ecma262/#sec-string.prototype.matchall).

Most common usage:
```js
const assert = require('assert');
const matchAll = require('string.prototype.matchall');

const str = 'aabc';
const nonRegexStr = 'ab';
const globalRegex = /[ac]/g;
const nonGlobalRegex = /[bc]/i;

// non-regex arguments are coerced into a global regex
assert.deepEqual(
	[...matchAll(str, nonRegexStr)],
	[...matchAll(str, new RegExp(nonRegexStr, 'g'))]
);

assert.deepEqual([...matchAll(str, globalRegex)], [
	Object.assign(['a'], { index: 0, input: str, groups: undefined }),
	Object.assign(['a'], { index: 1, input: str, groups: undefined }),
	Object.assign(['c'], { index: 3, input: str, groups: undefined }),
]);

assert.throws(() => matchAll(str, nonGlobalRegex)); // non-global regexes throw

matchAll.shim(); // will be a no-op if not needed

// non-regex arguments are coerced into a global regex
assert.deepEqual(
	[...str.matchAll(nonRegexStr)],
	[...str.matchAll(new RegExp(nonRegexStr, 'g'))]
);

assert.deepEqual([...str.matchAll(globalRegex)], [
	Object.assign(['a'], { index: 0, input: str, groups: undefined }),
	Object.assign(['a'], { index: 1, input: str, groups: undefined }),
	Object.assign(['c'], { index: 3, input: str, groups: undefined }),
]);

assert.throws(() => matchAll(str, nonGlobalRegex)); // non-global regexes throw

```

## Tests
Simply clone the repo, `npm install`, and run `npm test`

[package-url]: https://npmjs.com/package/string.prototype.matchall
[npm-version-svg]: https://versionbadg.es/es-shims/String.prototype.matchAll.svg
[deps-svg]: https://david-dm.org/es-shims/String.prototype.matchAll.svg
[deps-url]: https://david-dm.org/es-shims/String.prototype.matchAll
[dev-deps-svg]: https://david-dm.org/es-shims/String.prototype.matchAll/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/String.prototype.matchAll#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/string.prototype.matchall.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/string.prototype.matchall.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/string.prototype.matchall.svg
[downloads-url]: https://npm-stat.com/charts.html?package=string.prototype.matchall
[codecov-image]: https://codecov.io/gh/es-shims/String.prototype.matchAll/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/String.prototype.matchAll/
[actions-image]: https://img.shields.io/github/check-runs/es-shims/String.prototype.matchAll/main
[actions-url]: https://github.com/es-shims/String.prototype.matchAll/actions

---
_Source: https://npm.io/package/string.prototype.matchall · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
