Strings.replace()

Replace parts of a string that match a given regular expression with the specified replacement.

Usage

Hover over inputs/exits for more info.

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


// Replace parts of a string that match a given regular expression with the specified replacement.

Strings.replace({

string: 'Hello world!',

regexp: 'World',

replacement: 'Mumbai',

caseInsensitive: true,

global: true,

multiline: true,

}).execSync();

Inputs

string required

The string to modify.

'Hello world!'
regexp required

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

'World'
replacement required

The string to use when replacing matches.

'Mumbai'
caseInsensitive

Whether or not you care about uppercase/lowercase letters.

true
global

Whether or not to replace all substrings that match the regular expression, or just the first.

true
multiline

Whether to treat beginning and end characters (^ and $) as matching each line delimited by \n or \r.

true

Exits

error

An unexpected error occurred.

invalidRegexp

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

success

OK.

'Hello Mumbai!'