1// Javascript Regex Reference
2// /abc/ A sequence of characters
3// /[abc]/ Any character from a set of characters
4// /[^abc]/ Any character not in a set of characters
5// /[0-9]/ Any character in a range of characters
6// /x+/ One or more occurrences of the pattern x
7// /x+?/ One or more occurrences, nongreedy
8// /x*/ Zero or more occurrences
9// /x?/ Zero or one occurrence
10// /x{2,4}/ Two to four occurrences
11// /(abc)/ A group
12// /a|b|c/ Any one of several patterns
13// /\d/ Any digit character
14// /\w/ An alphanumeric character (“word character”)
15// /\s/ Any whitespace character
16// /./ Any character except newlines
17// /\b/ A word boundary
18// /^/ Start of input
19// /$/ End of input
1// \d Any digit character
2// \w An alphanumeric character (“word character”)
3// \s Any whitespace character (space, tab, newline, and similar)
4// \D A character that is not a digit
5// \W A nonalphanumeric character
6// \S A nonwhitespace character
7// . Any character except for newline
8// /abc/ A sequence of characters
9// /[abc]/ Any character from a set of characters
10// /[^abc]/ Any character not in a set of characters
11// /[0-9]/ Any character in a range of characters
12// /x+/ One or more occurrences of the pattern x
13// /x+?/ One or more occurrences, nongreedy
14// /x*/ Zero or more occurrences
15// /x?/ Zero or one occurrence
16// /x{2,4}/ Two to four occurrences
17// /(abc)/ A group
18// /a|b|c/ Any one of several patterns
19// /\d/ Any digit character
20// /\w/ An alphanumeric character (“word character”)
21// /\s/ Any whitespace character
22// /./ Any character except newlines
23// /\b/ A word boundary
24// /^/ Start of input
25// /$/ End of input
1//Adding '/' around regex
2var regex = /\s/g;
3//or using RegExp
4var regex = new RegExp("\s", "g");
1// Regular expression match sequence of characters
2console.log(/abc/.test("abcde")); // true
3console.log(/abc/.test("abxde")); // false
1// Tests website Regular Expression against document.location (current page url)
2if (/^https\:\/\/example\.com\/$/.exec(document.location)){
3 console.log("Look mam, I can regex!");
4}