Answers for "expresiones regulares javascript"

3

expresiones regulares javascript

var text = "este es un texto de prueba";
var regEx = /este/gi;

console.log(regEx.test(text)) // true
Posted by: Guest on June-06-2020
0

pass variable to regrex literal notation javascript

// 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):

re = new RegExp(`\\b${replaceThis}\\b`, 'gi');

// example:

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")); // I'm Jack, or johnny, but I prefer Jack.
Posted by: Guest on December-26-2020
9

regular expression javascript

// Tests website Regular Expression against document.location (current page url)
if (/^https\:\/\/example\.com\/$/.exec(document.location)){
	console.log("Look mam, I can regex!");
}
Posted by: Guest on March-12-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language