The replace function returns the new string with the replaces, but if there weren\'t any words to replace, then the original string is returned. Is there a way to k
replace
Use .test()
.test()
const regex = /foo/; const yourString = 'foo bar'; if (regex.test(yourString)) { console.log('yourString contains regex'); }
The test() method executes a search for a match between a regular expression and a specified string. Returns true or false.