Regex Flashcards
Simple Class:
[abc]
[abc]
Matches on
a, b, or, c
Negation of class
[^abc]
[^abc]
Matches on
Any character except for a, b, or, c
Range class:
[a-zA-Z]
[a-zA-Z]
Matches on
a through z or A through Z inclusive
Union of ranges
[a-d[m-p]]
A single class that combines two seperate ranges
[a-d[m-p]]
Matches
Characters a through d or characters m through p inclusive
This is a union of ranges
Intsersection of classes:
[a-z&&[def]]
Creates a single class that will only match on characters that are in each sub class
[a-z&&[def]]
Matches on
Characters d, e, and f
This is an intersection and only matches on characters in both [a-z] and [def]
Subtraction:
[a-z&&[^m-p]
Creates a single class that will only match on characters that are in one class but not the other i.e. anything between a-z as long as it’s not between m-p inclusive
[a-z&&[^m-p]]
Matches on
Anything between a-z that is not between m-p
Predefined Class
Match any character
.
Predefined class
.
Matches
Any character
Predefined Class
Match any digit
\d
Equal to the class [0-9]