js regex from string code example

Example 1: les fonctions reguliere javascript

if(! pseudo.match(/^([a-zA-Z ]+)$/))
    alert('Pseudo invalide');

Example 2: js string to regex

const regex = new RegExp('https:\\/\\/\\w*\\.\\w*.*', 'g');

Example 3: using regex in javascript

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

Example 4: regex for strings with specific letters javascript

let re = /ab+c/;

Example 5: 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!");
}

Tags:

Java Example