Character Classes Basics: Javascript Regex Cheatsheet
This document provides a cheatsheet for JavaScript regular expressions (regex). It outlines regex basics like characters, character classes, groups, lookarounds, quantifiers, alternations, anchors, and flags. It also gives examples for common regex patterns like validating emails, URLs, numbers, and alphanumeric strings.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
75 views1 page
Character Classes Basics: Javascript Regex Cheatsheet
This document provides a cheatsheet for JavaScript regular expressions (regex). It outlines regex basics like characters, character classes, groups, lookarounds, quantifiers, alternations, anchors, and flags. It also gives examples for common regex patterns like validating emails, URLs, numbers, and alphanumeric strings.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
JavaScript Regex Cheatsheet
Basics Character Classes
. any character except newline \w \d \s word digit whitespace a the character a \W \D \S not word digit whitespace ab the string ab [abc] any of a, b, or c a|b a or b [^abc] not a, b, or c a* 0 or more a’s [a-g] characters between a & g \ escapes a special character Anchors Groups & Lookaround ^abc$ start / end of the string (abc) capture group \b \B word, not-word boundary \1 backreference to group #1 (?:abc) non-capturing group Escaped Characters (?=abc) positive lookahead \. \* \\ escaped special characters (?!abc) negative lookahead \t \n \r tab, linefeed, carriage return
Quantifiers & Alt Common Examples
a* a+ a? 0 or more, 1 or more, 0 or 1 ^\d+$ whole numbers
a{5} a{2,} exactly five, two or more ^[a-zA-Z0-9]*$
alphanumeric with space a{1,3} between one & three a+? a{2,}? match as few as possible /\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b/i email address ab|cd match ab or cd ^(https?:\/\/)?([\da-z\.-]+\.[a-z\.]{2,6}|[ Flags \d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?$ url validation g global i case insensitive m multiline