regex MDN code example

Example 1: javascript new Regexp with flag

new RegExp(/ab+c/, 'i') // literal notation
new RegExp('ab+c', 'i') // constructor

const pattern='some pattern';
new RegExp(pattern)

Example 2: les fonctions reguliere javascript

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

Example 3: js string to regex

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

Example 4: using regex in javascript

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

Example 5: regex for strings with specific letters javascript

let re = /ab+c/;

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