regx js code example

Example 1: using regex in javascript

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

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

Example 3: javascript regex match sequence

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