1var text = "este es un texto de prueba";
2var regEx = /este/gi;
3
4console.log(regEx.test(text)) // true
1// If you want to get ALL occurrences (g), be case insensitive (i), and use boundaries so that it isn't a word within another word (\\b):
2
3re = new RegExp(`\\b${replaceThis}\\b`, 'gi');
4
5// example:
6
7let inputString = "I'm John, or johnny, but I prefer john.";
8let replaceThis = "John";
9let re = new RegExp(`\\b${replaceThis}\\b`, 'gi');
10console.log(inputString.replace(re, "Jack")); // I'm Jack, or johnny, but I prefer Jack.
11
1// Tests website Regular Expression against document.location (current page url)
2if (/^https\:\/\/example\.com\/$/.exec(document.location)){
3 console.log("Look mam, I can regex!");
4}