KEMBAR78
Pattern Cheatsheet | PDF | Regular Expression | Computer Programming
0% found this document useful (0 votes)
8 views1 page

Pattern Cheatsheet

pattern cheatsheet helps in the rivison of pattern
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
8 views1 page

Pattern Cheatsheet

pattern cheatsheet helps in the rivison of pattern
Copyright
© © All Rights Reserved
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

Regular Expression Cheatsheet

HTML Input Attributes Quantifiers


Syntax Description
Attribute Description
{n} Exactly n occurrences
id Unique identifier
{n,m} Between n and m
name Form field name
{n,} At least n
class CSS class
value Default value
size Input width Common Examples
placeholder Hint text
readonly Read-only field Pattern Matches
disabled Disabled field
autofocus Auto-focus on load .at cat, bat, rat, 2at
minlength Minimum length \+91 +91
maxlength Maximum length gmail\.com gmail.com
required Required field red|green|blue red, green, blue
list Datalist reference \d\d? 1, 4, 33, 23
pattern Regex validation \d\D\d 4A5, 3$4
\d{4} 4-digit number
\d{2,4} 2-4 digit number
\w{4,10} 4-10 word chars
Basic Meta Characters
Practical Patterns
Char Description
Indian Mobile Number:
? Zero or one occurrence pattern="\+91\d{10}"
* Zero or more occurrences pattern="\+91[0-9]{10}"
+ One or more occurrences US Mobile Format:
. Any single character +(1)(000) 000-0000
\ Escape meta character pattern="\+\(1\)\(\d{3}\)\s\d{3}-\d{4}"
| Logical OR Email Pattern:
() Grouping/priority [a-z,A-Z,0-9]+@[a-z,A-Z,0-9]+\.[a-z,A-Z]{2,4}
[] Character set Strong Password:
[^] Negated character set [^\s]{8,} (8+ chars, no spaces)
^ Start of string URL Pattern:
$ End of string https?://[a-z,A-Z,0-9.-]+\.[a-z]{2,4}

Quick Reference
Character Classes • Use \ to escape special characters
• [^] negates character sets
Class Description
\d Digits [0-9] • | acts as logical OR
\D Non-digits • () groups expressions
\w Word chars [A-Z,a-z,0-9, ]
\W Non-word chars • ^ anchors to start, $ to end
\s Whitespace
• ? makes preceding optional
\i Case insensitive
• * allows zero or more
• + requires one or more
Character Sets
Tips
Pattern Matches
• Test patterns with sample data
[a,d,s] Only specified chars
[a-z] Lowercase letters • Use online regex testers
[A-Z] Uppercase letters • Start simple, add complexity
[0-9] Single digit
[a-z,A-Z] All letters • Escape dots in domains: gmail\.com
[a-z,A-Z,0-9]Alphanumeric
• Use anchors (^$) for exact matches
[^a,d,s] Excludes specified
[^A-Z,0-9] Excludes range • Remember is included in \w

You might also like