“Expresiones Regulares JavaScript” Kode Jawaban

lulus variabel ke notasi literal regrex 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.
Kelly

Expresiones Regulares JavaScript

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

console.log(regEx.test(text)) // true
Antoniotonio

JavaScript ekspresi reguler

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

Jawaban yang mirip dengan “Expresiones Regulares JavaScript”

Pertanyaan yang mirip dengan “Expresiones Regulares JavaScript”

Lebih banyak jawaban terkait untuk “Expresiones Regulares JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya