“Regelmäßiger Ausdruck Javascript” Code-Antworten

JavaScript Regex

//Declare Reg using slash
let reg = /abc/
//Declare using class, useful for buil a RegExp from a variable
reg = new RegExp('abc')

//Option you must know: i -> Not case sensitive, g -> match all the string
let str = 'Abc abc abc'
str.match(/abc/) //Array(1) ["abc"] match only the first and return
str.match(/abc/g) //Array(2) ["abc","abc"] match all
str.match(/abc/i) //Array(1) ["Abc"] not case sensitive
str.match(/abc/ig) //Array(3) ["Abc","abc","abc"]
//the equivalent with new RegExp is
str.match('abc', 'ig') //Array(3) ["Abc","abc","abc"]
POG

Verwenden von Regex in JavaScript

//Adding '/' around regex
var regex = /\s/g;
//or using RegExp
var regex = new RegExp("\s", "g");
TC5550

Expressiones reguläre JavaScript

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

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

JavaScript Regex Ein oder mehrere Ereignisse des Musters

// Regular expression 1 or more occurrences of the pattern
console.log(/'\d+'/.test("'123'")); // true
console.log(/'\d+'/.test("''")); // false

let cartoonCrying = /boo+(hoo+)+/i;
console.log(cartoonCrying.test("Boohoooohoohooo"));// true
Code Wrangler

JavaScript Regex Match -Sequenz

// Regular expression match sequence of characters
console.log(/abc/.test("abcde")); // true
console.log(/abc/.test("abxde")); // false
Code Wrangler

Regelmäßiger Ausdruck 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!");
}
Kaotik

Ähnliche Antworten wie “Regelmäßiger Ausdruck Javascript”

Fragen ähnlich wie “Regelmäßiger Ausdruck Javascript”

Weitere verwandte Antworten zu “Regelmäßiger Ausdruck Javascript” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen