Playground for practice https://regexr.com/ https://regex101.com/
Pattern Matching
Regex Syntax
/<regex pattern>/
Starts with wild card character
^
Ends with wcc
$
set enclosed in
[set]
[^invert-set]
only numbers
^[0-9]+$
^\d+$
only characters
^[a-zA-Z]+$
^\w+$
occurance wcc
* => any number of occurrence
? => 0 or 1 occurrence
+ => 1 or many occurrence
e.g. adarsh mishra
to match 1 space /adarsh\smishra/
to match multiple space /adarsh\s+mishra/
to match 0 or many spaces /adarsh\s*mishra/
no special characters
^[0-9a-zA-Z\s]+$
limited characters or numbers
^[0-9]{6}$
^[a-z]{3}$
min / max range characters or numbers
^[0-9]{3,6}$
^[a-z]{3,6}$
OR clause
^(chacha|bhatija)$
case insensitive
//i
global check
//g
search any pattern
(.) e.g. “https://www.youtube.com/watch?v=hw_HpTI_Wkw”.match(/v=(.)/)[1]
will return video id hw_HpTI_Wkw
Assignment
- girls / boys name
- phone number
- find Indian zip code
- valid name
- email id
- 8-12 character password
- aadhaar number
- pancard
- name starts with vowels
- names ends with vowels
- names having only 5 characters
- credit card number
Sample Text
1234567890
123453
DAVPS0412P
127836320613
9876543210
098762
xyz@yahoo.com
smita
&UJMmju7
shailesh
143258761937
priyanka
abc@gmail.com
112096851365
%TGBbgt5
priya