# oniguruma

> oniguruma regular expression library

Latest version **7.2.3** (published 2021-07-02) · 0 weekly downloads

## Install

```sh
npm install oniguruma
pnpm add oniguruma
yarn add oniguruma
bun add oniguruma
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.2.3 |
| Published | 2021-07-02 |
| First published | 2013-03-06 |
| Weekly downloads | 0 |
| TypeScript types | separate (@types/oniguruma) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 2.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 121 |
| Maintainers | benogle, nathansobo, kevinsawicki, maxbrunsfeld, zcbenz, zeke, atom-team, kashef |
| Keywords | regex, regexp, re, regular expression, async |

## Links

- npm: https://www.npmjs.com/package/oniguruma
- Repository: https://github.com/atom/node-oniguruma
- Homepage: http://atom.github.io/node-oniguruma
- Issues: https://github.com/atom/node-oniguruma/issues
- npm.io page: https://npm.io/package/oniguruma

## Dependencies (1)

- [nan](https://npm.io/package/nan.md) ^2.14.0

## 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

- 7.2.3 (latest) — 2021-07-02
- 7.2.1 — 2019-11-12
- 7.2.0 — 2019-06-06
- 7.1.0 — 2019-04-26
- 7.0.2 — 2018-09-19
- 7.0.1 — 2018-07-23
- 7.0.0 — 2017-09-08
- 6.2.1 — 2017-04-20
- 6.2.0 — 2017-04-19
- 6.2.0-2 — 2017-04-19
- 6.2.0-1 — 2017-04-19
- 6.2.0-0 — 2017-04-18
- 6.1.1 — 2016-09-20
- 6.1.0 — 2016-05-07
- 6.0.1 — 2016-01-29
- … 54 more at https://npm.io/package/oniguruma/versions

## README

# Oniguruma Node module
[![CI](https://github.com/atom/node-oniguruma/actions/workflows/ci.yml/badge.svg)](https://github.com/atom/node-oniguruma/actions/workflows/ci.yml)

Native Node bindings to the Oniguruma regular expressions library.

Read all about Oniguruma regular expressions [here](https://github.com/kkos/oniguruma/blob/master/doc/RE).

Version 2.0 of this library added an asynchronous API, the old synchronous
methods have been renamed to have a `Sync` suffix.

## Installing

```sh
npm install oniguruma
```

## Building
  * Clone the repository
  * Run `npm install`
  * Run `npm test` to run the specs

## Using

```coffeescript
{OnigRegExp, OnigScanner} = require 'oniguruma'
```

### OnigScanner(patterns)

Create a new scanner with the given patterns.

`patterns` - An array of string patterns.

### OnigScanner::findNextMatch(string, startPosition, callback)

Find the next match from a given position.

`string` - The string to search.

`startPosition` - The optional position to start at, defaults to `0`.

`callback` - The `(error, match)` function to call when done, `match` will
null when there is no match.

#### Example

```coffeescript
scanner = new OnigScanner(['c', 'a(b)?'])
scanner.findNextMatch 'abc', (error, match) ->
  console.log match
  {
    index: 1,  # Index of the best pattern match
    captureIndices: [
      {index: 0, start: 0, end: 2, length: 2},  # Entire match
      {index: 1, start: 1, end: 2, length: 1}   # Match of first capture group
    ]
  }
```

### OnigScanner::findNextMatchSync(string, startPosition)

Synchronously find the next match from a given position.

`string` - The string to search.

`startPosition` - The optional position to start at, defaults to `0`.

Returns an object containing details about the match or `null` if no match.

#### Example

```coffeescript
scanner = new OnigScanner(['c', 'a(b)?'])
match = scanner.findNextMatchSync('abc')
console.log match
{
  index: 1,  # Index of the best pattern match
  captureIndices: [
    {index: 0, start: 0, end: 2, length: 2},  # Entire match
    {index: 1, start: 1, end: 2, length: 1}   # Match of first capture group
  ]
}
```

### OnigRegExp(pattern)

Create a new regex with the given pattern.

`pattern` - A string pattern.

### OnigRegExp::search(string, startPosition, callback)

Search the string for a match starting at the given position.

`string` - The string to search.

`startPosition` - The optional position to start the search at, defaults to `0`.

`callback` - The `(error, match)` function to call when done, `match` will be
null if no matches were found. `match` will be an array of objects for each
matched group on a successful search.

#### Example

```coffeescript
regex = new OnigRegExp('a([b-d])c')
regex.search '!abcdef', (error, match) ->
  console.log match
  [
    {index: 0, start: 1, end: 4, match: 'abc', length: 3}, # Entire match
    {index: 1, start: 2, end: 3, match: 'b', length: 1}    # Match of first capture group
  ]
```

### OnigRegExp::searchSync(string, startPosition)

Synchronously search the string for a match starting at the given position.

`string` - The string to search.

`startPosition` - The optional position to start the search at, defaults to `0`.

Returns an array of objects for each matched group or `null` if no match was
found.

#### Example

```coffeescript
regex = new OnigRegExp('a([b-d])c')
match = regex.searchSync('!abcdef')
console.log match
[
  {index: 0, start: 1, end: 4, match: 'abc', length: 3}, # Entire match
  {index: 1, start: 2, end: 3, match: 'b', length: 1}    # Match of first capture group
]
```

### OnigRegExp::test(string, callback)

Test if this regular expression matches the given string.

`string` - The string to test against.

`callback` - The `(error, matches)` function to call when done, `matches` will
be `true` if at least one match is found, `false` otherwise.

#### Example

```coffeescript
regex = new OnigRegExp('a([b-d])c')
regex.test 'abcdef', (error, matches) ->
  console.log matches # true
```

### OnigRegExp::testSync(string)

Synchronously test if this regular expression matches the given string.

`string` - The string to test against.

Returns `true` if at least one match, `false` otherwise.

#### Example

```coffeescript
regex = new OnigRegExp('a([b-d])c')
matches = regex.testSync('abcdef')
console.log matches # true
```

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