# regex-format

> Format regex with string substitutions

Latest version **0.3.2** (published 2016-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install regex-format
pnpm add regex-format
yarn add regex-format
bun add regex-format
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2016-11-01 |
| First published | 2014-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Eugene Sharygin |
| Maintainers | eush77 |
| Keywords | format, escape, string, regex, regexp, re, regular, expression, formatting, substitution |

## Links

- npm: https://www.npmjs.com/package/regex-format
- Repository: https://github.com/eush77/regex-format
- Issues: https://github.com/eush77/regex-format/issues
- npm.io page: https://npm.io/package/regex-format

## Dependencies (4)

- [traverse](https://npm.io/package/traverse.md) ^0.6.6
- [string-format](https://npm.io/package/string-format.md) ^0.5.0
- [lodash.flowright](https://npm.io/package/lodash.flowright.md) ^3.5.0
- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^1.0.2

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2016-11-01
- 0.3.1 — 2016-10-31
- 0.3.0 — 2015-08-12
- 0.2.1 — 2015-06-13
- 0.2.0 — 2014-10-10
- 0.1.1 — 2014-10-02
- 0.1.0 — 2014-10-02

## README

# regex-format [![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david] [![DevDependency Status][david-dev-badge]][david-dev]

[![npm](https://nodei.co/npm/regex-format.png)](https://nodei.co/npm/regex-format/)

[travis-badge]: https://travis-ci.org/eush77/regex-format.svg
[travis]: https://travis-ci.org/eush77/regex-format
[david-badge]: https://david-dm.org/eush77/regex-format.png
[david]: https://david-dm.org/eush77/regex-format
[david-dev-badge]: https://david-dm.org/eush77/regex-format/dev-status.png
[david-dev]: https://david-dm.org/eush77/regex-format?type=dev

Format regex with string substitutions.

## Example

```js
regexFormat(/^Author:\s+{#name} <{#email}>$/, {
  name: 'someone',
  email: 'someone@example.com'
})
//=> /^Author:\s+someone <someone@example\.com>$/

regexFormat(/^{}$/, 'foo$1')
//=> /^foo\$1$/
```

## API

### regexFormat(spec, [values]...)

`spec` is a RegExp, otherwise it is converted to RegExp. Flags are preserved.

The syntax for substitutions is the same as accepted by [string-format](https://www.npmjs.org/package/string-format), except that non-empty groups are prepended with a hash sign: `{#0}`, `{#foo.bar}`, etc (empty groups are still `{}`).

## Install

```shell
npm install regex-format
```

## License

MIT

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