expresiones regulares javascript code example
Example 1: expresiones regulares javascript
var text = "este es un texto de prueba";
var regEx = /este/gi;
console.log(regEx.test(text))
Example 2: pass variable to regrex literal notation javascript
re = new RegExp(`\\b${replaceThis}\\b`, 'gi');
let inputString = "I'm John, or johnny, but I prefer john.";
let replaceThis = "John";
let re = new RegExp(`\\b${replaceThis}\\b`, 'gi');
console.log(inputString.replace(re, "Jack"));
Example 3: regular expression javascript
if (/^https\:\/\/example\.com\/$/.exec(document.location)){
console.log("Look mam, I can regex!");
}