boundary-match
![Coverage percentage](https://coveralls.io/repos/busterc/boundary-match/badge.svg)
Regex string match and replace that honors boundaries for targets prepended and/or appended with non-word characters.
Installation
$ npm install --save boundary-match
Usage
const boundaryMatch = require('boundary-match');
boundaryMatch('(HotDog)', '(hotdog)', 'i');
'(HotDog)'.match(/\b\(hotdog\)\b/i);
'(HotDog)'.match(new RegExp('\\b\\(hotdog\\)\\b', 'i'));
let matched = boundaryMatch('Gimme a (HotDog)', '(HOTDOG)', 'i');
boundaryMatch.replace(matched, 'Chili Dog!');
API
boundaryMatch(string, target[, flags])
If the target
is found in the string
, it returns an Array
containing the entire matched target as the first element; an index
property for the start of the match; and an input
property that contains the entire string
. If there were no matches, null
is returned.
-
string
Required
: String
the string to be searched.
-
target
-
flags
Optional
: String
can have any combination of the following values:
boundaryMatch.replace(match, target)
Returns a String
that replaces the found match
results with target
-
match
Required
: Array
the result of previously calling boundaryMatch
-
target
Required
: String
the string that replaces the found match
TODO
- [] Implement other native
RegExp
flags: g
,u
, m
, y
FYI
License
ISC © Buster Collings