# issue-regex

> Regular expression for matching issue references

Latest version **4.3.0** (published 2024-09-25) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.3.0 |
| Published | 2024-09-25 |
| First published | 2017-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 49 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | issue, issues, pr, pull, request, reference, references, regex, regexp, regular, expression, github, gh, link |

## Links

- npm: https://www.npmjs.com/package/issue-regex
- Repository: https://github.com/sindresorhus/issue-regex
- Homepage: https://github.com/sindresorhus/issue-regex#readme
- Issues: https://github.com/sindresorhus/issue-regex/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/issue-regex

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 4.3.0 (latest) — 2024-09-25
- 4.2.0 — 2024-09-07
- 4.1.0 — 2022-06-11
- 4.0.0 — 2021-08-10
- 3.1.0 — 2019-04-21
- 3.0.0 — 2019-02-05
- 2.0.0 — 2018-05-06
- 1.0.0 — 2017-06-02

## README

# issue-regex

> Regular expression for matching issue references

## Install

```sh
npm install issue-regex
```

## Usage

```js
import issueRegex from 'issue-regex';

'Fixes #143 and avajs/ava#1023'.match(issueRegex());
//=> ['#143', 'avajs/ava#1023']
```

Organization name, repository name, and issue number are also available individually in capturing groups 1-3, or named groups `organization`, `repository`, and `issueNumber`:

```js
issueRegex().exec('Fixes avajs/ava#1023');
/*
[
	'avajs/ava#1023',
	'avajs',
	'ava',
	'1023',
	index: 6,
	input: 'Fixes avajs/ava#1023',
	groups: {
		organization: 'avajs',
		repository: 'ava',
		issueNumber: '1023'
	}
]
*/
```

## API

### issueRegex(options?)

Returns a `RegExp` for matching issue references.

### options

Type: `object`

#### additionalPrefix

Support for references like `GH-123` can be added manually. Adding a prefix will still match the #-based references:

```js
import issueRegex from 'issue-regex';

issueRegex({additionalPrefix: 'GH-'}).exec('GH-123');
//=> ['GH-123', 'GH-', '123']

'Fixes GH-143 and avajs/ava#1023'.match(issueRegex({additionalPrefix: 'GH-'}));
//=> ['GH-143', 'avajs/ava#1023']
```

> [!NOTE]
> `additionalPrefix` is added unescaped to the regex, keep it simple.

## Important

If you run the regex against untrusted user input in a server context, you should [give it a timeout](https://github.com/sindresorhus/super-regex).

**I do not consider ReDoS a valid vulnerability for this package.**

## Related

- [linkify-issues](https://github.com/sindresorhus/linkify-issues) - Linkify GitHub issue references

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