7.2.3 • Published 3 years ago

oniguruma v7.2.3

Weekly downloads
14,805
License
-
Repository
github
Last release
3 years ago

Oniguruma Node module

CI

Native Node bindings to the Oniguruma regular expressions library.

Read all about Oniguruma regular expressions here.

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

Installing

npm install oniguruma

Building

  • Clone the repository
  • Run npm install
  • Run npm test to run the specs

Using

{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

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

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

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

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

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

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

3 years ago

7.2.1

4 years ago

7.2.0

5 years ago

7.1.0

5 years ago

7.0.2

6 years ago

7.0.1

6 years ago

7.0.0

7 years ago

6.2.1

7 years ago

6.2.0

7 years ago

6.2.0-2

7 years ago

6.2.0-1

7 years ago

6.2.0-0

7 years ago

6.1.1

8 years ago

6.1.0

8 years ago

6.0.1

8 years ago

6.0.0

8 years ago

5.1.2

8 years ago

5.1.1

9 years ago

4.2.4

9 years ago

4.2.3

9 years ago

5.1.0

9 years ago

5.0.1

9 years ago

5.0.0

9 years ago

4.2.2

9 years ago

4.2.1

9 years ago

4.2.0

9 years ago

4.1.0

9 years ago

4.0.0

9 years ago

3.1.0

9 years ago

3.0.6

9 years ago

3.0.5

9 years ago

3.0.4

10 years ago

3.0.3

10 years ago

3.0.2

10 years ago

3.0.1

10 years ago

3.0.0

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.26.0

10 years ago

0.25.0

10 years ago

0.24.0

10 years ago

0.23.0

10 years ago

0.22.0

10 years ago

0.21.0

10 years ago

0.20.0

11 years ago

0.19.0

11 years ago

0.18.0

11 years ago

0.17.0

11 years ago

0.16.0

11 years ago

0.15.0

11 years ago

0.14.0

11 years ago

0.13.0

11 years ago

0.12.0

11 years ago

0.11.0

11 years ago

0.10.0

11 years ago

0.9.0

11 years ago

0.8.0

11 years ago

0.7.0

11 years ago

0.6.0

11 years ago

0.5.0

11 years ago

0.4.0

11 years ago

0.3.0

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago