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]
Predefined Class
\d
Matches
Any digit
[0-9]
Predefined Class
Match any non-digit character
\D
Equal to: [^0-9]
Predefined Class
\D
Matches
Any non-digit
[^0-9]
Predefined Class
Match a whitespace
\s
Equal to: [\t\n\x0B\f\r]
Predefined Class
/s
Matches
Any whitespace character
[\t\n\x0B\f\r]
Predefined Class
Match any non whitespace character
\S
Equal to: [^\s]
Predefined Class
/S
Matches
Any non-whitespace character
[^\s]
Predefined Class
Match any word character
\w
Equal to: [a-zA-Z_0-9]
Predefined Class
\w
Matches on
Any word character
[a-zA-Z_0-9]
Predefined Class
Match any non-word character
\W
Equal to: [^\w]
Predefined Class
\W
Matches on
Any non-word character
[^\w]