0
Q:

what is regular expression in javascript

let re = /ol/, 
Characters \, ., \cX, \d, \D, \f, \n, \r, \s, \S, \t, \v, \w, \W, \0, \xhh, \uhhhh, \uhhhhh, [\b]	
Assertions 	^, $, x(?=y), x(?!y), (?<=y)x, (?<!y)x, \b, \B
Groups 		(x), (?:x), (?<Name>x), x|y, [xyz], [^xyz], \Number	
Quantifiers *, +, ?, x{n}, x{n,}, x{n,m}
Unicode \p{UnicodeProperty}, \P{UnicodeProperty}	 property escapes
let defaults = new RegExp('compiled'); 
defaults = { dotAll: false, flags: "", global: false, ignoreCase: false, falselastIndex: 0, multiline: false, source: "abc", sticky: false, unicode: false}
4
// Tests website Regular Expression against document.location (current page url)
if (/^https\:\/\/example\.com\/$/.exec(document.location)){
	console.log("Look mam, I can regex!");
}
8
// 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
0
// Regular expression match sequence of characters
console.log(/abc/.test("abcde")); // true
console.log(/abc/.test("abxde")); // false
0

New to Communities?

Join the community