Back to Jsverbalexpressions

Miscellaneous

docs/VerbalExpression/miscellaneous.md

1.0.2929 B
Original Source

Miscellaneous

replace

Replace characters matching the VerbalExpression in a string with another string.

ParameterExpected typeDescription
sourceStringString to look for matches in
valueStringString to replace matches with

Return type: String

js
const spaces = VerEx().find(' ');
const fileName = 'a file name.txt';

// => 'a_file_name.txt'
console.log(spaces.replace(fileName, '_'));

toRegExp

Convert the class to a RegExp object.

Return type: RegExp

js
const expr = VerEx().find('foo');
console.log(expr.toRegExp()); // => /(?:foo)/gm