Strings.match()

Search a string using a regular expression and return the first match.

Usage

Hover over inputs/exits for more info.

var Strings = require('machinepack-strings');


// Search a string using a regular expression and return the first match.

Strings.match({

string: 'hello world',

regexp: 'world',

caseInsensitive: true,

}).execSync();

Inputs

string required

The string to search (i.e. "haystack")

'hello world'
regexp required

The regular expression to match against (i.e. "metal detector")

'world'
caseInsensitive

Whether or not you care about uppercase/lowercase letters.

true

Exits

error

An unexpected error occurred.

invalidRegexp

Provided regular expression is invalid (cannot be instantiated into a RegExp object)

notFound

No match found.

success

OK.

{ found: 'world', at: 6 }