# regexp-util

> utilities for generating regular expression

Latest version **2.1.0** (published 2026-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install regexp-util
pnpm add regexp-util
yarn add regexp-util
bun add regexp-util
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2026-09-16 |
| First published | 2018-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 18.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 10 |
| Author | Ika |
| Maintainers | fisker, ikatyang |
| Keywords | regex |

## Links

- npm: https://www.npmjs.com/package/regexp-util
- Repository: https://github.com/ikatyang-collab/regexp-util
- Homepage: https://github.com/ikatyang-collab/regexp-util#readme
- Issues: https://github.com/ikatyang-collab/regexp-util/issues
- npm.io page: https://npm.io/package/regexp-util

## Recent versions

- 2.1.0 (latest) — 2026-09-16
- 2.0.3 — 2025-03-08
- 2.0.2 — 2025-03-08
- 2.0.1 — 2025-03-07
- 2.0.0 — 2023-07-09
- 1.2.2 — 2018-03-21
- 1.2.1 — 2018-03-20
- 1.2.0 — 2018-02-09
- 1.1.0 — 2018-02-05
- 1.0.0 — 2018-02-05

## README

# regexp-util

[![npm](https://img.shields.io/npm/v/regexp-util.svg)](https://www.npmjs.com/package/regexp-util)
[![build](https://img.shields.io/github/actions/workflow/status/ikatyang/regexp-util/test.yml)](https://github.com/ikatyang/regexp-util/actions?query=branch%3Amain)

utilities for generating regular expression

[Changelog](https://github.com/ikatyang/regexp-util/blob/main/CHANGELOG.md)

## Install

```sh
npm install regexp-util
```

## Usage

```ts
import { charset } from 'regexp-util'

const regex = util
  .charset(['a', 'g']) // a ~ g
  .subtract(['c', 'e'])
  .toRegExp()

const aResult = 'a'.test(regex) //=> true
const dResult = 'd'.test(regex) //=> false
```

## API

### Base

```ts
declare abstract class Base {
  isEmpty(): boolean
  toString(flags?: string): string
  toRegExp(flags?: string): RegExp
}
```

### Charset

```ts
declare type CharsetInput =
  | Charset
  | string // char
  | number // codepoint
  | [string, string] // char: start to end (inclusive)
  | [number, number] // codepoint: start to end (inclusive)

declare function charset(...inputs: CharsetInput[]): Charset

declare class Charset extends Base {
  constructor(...inputs: CharsetInput[])
  union(...inputs: CharsetInput[]): Charset
  subtract(...inputs: CharsetInput[]): Charset
  intersect(...inputs: CharsetInput[]): Charset
}
```

## Development

```sh
# lint
pnpm run lint

# build
pnpm run build

# test
pnpm run test
```

## License

MIT © [Ika](https://github.com/ikatyang)

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