Pattern Matching and Regex Flashcards
Start With
End with
$
Any single character
.
Zero or one
?
zero or many
*
One or many
+
OR operator
|
[abc]
:set
[^abc]
:set not equal
[a-f]
:range
[^a-f]
:range not equal
~
True/False Regex:
Tests the value on the left against the regex on the right and returns true if the regex can match within the value.
Note that the regex does not have to fully match the whole value, it just has to match a part.
text ~ text → boolean
String matches regular expression, case sensitively
‘thomas’ ~ ‘t.*ma’ → t
~*
True/False Regex:
Case insensitive version of ~.
Tests the value on the left against the regex on the right and returns true if the regex can match within the value.
text ~* text → boolean
String matches regular expression, case insensitively
‘thomas’ ~* ‘T.*ma’ → t
.
Matches any character
\s
Matches “empty space” characters like space and tab