RegEx Special Characters Flashcards
\d
-Matches a digit from 0 to 9
“1” “A” (no match) “_” (no match) “!” (no match) “ ” (no match)
\d
-Matches a digit from 0 to 9
“1” “A” (no match) “_” (no match) “!” (no match) “ ” (no match)
\D
-Matches a non-digit
“1” (no match) “A” “_” “!” “ ”
\w
-Matches a word character (letter, digit, or underscore)
“1” “A” “_” “!” (no match) “ ” (no match)
\W
-Matches any non-word characters
“1” (no match) “A” (no match) “_” (no match) “!” “ ”
\s
-Matches any whitespace character, such as spaces and tabs
“1” (no match) “A” (no match) “_” (no match) “!” (no match) “ ”
\S
-Matches any non-whitespace character
“1” “A” “_” “!” “ ” (no match)
[…]
-Character Set:
+Matches any characters inside the brackets
+Can specify ranges of characters as well
Example set: "[A-C]" “A” “B” “C” “D” (no match) “E” (no match)
[^…]
-Negative Character Set:
+Matches anything NOT inside the brackets
Example set:"[^C-E]" “A” “B” “C” (no match) “D” (no match) “E” (no match)
.
-Wildcard: matches any character (except a newline)
“1” “A” “_” “!” “ ”
*
-Matches 0 or more times
Example: "ca*t" “ct” “cat” “caat” “caaat” “caaaat”
+
-Matches 1 or more times
Example: "ca+t" “ct” (no match) “cat” “caat” “caaat” “caaaat”
?
-Matches 0 or 1 times
Example: "ca?t" “ct” “cat” “caat” (no match) “caaat” (no match) “caaaat” (no match)
{#,}
-Matches at least a specific number of times
Example: "ca{2,}t" “ct” (no match) “cat” (no match) “caat” “caaat” “caaaat”
{# , #}
-Matches within a specific range of times
Example: "ca{2,3}t" “ct” (no match) “cat” (no match) “caat” “caaat” “caaaat” (no match)
|
-Alteration: matches either the expression before or the expression after (OR)
Example: “cat|dog”
“cat”
“dog”
“bird” (no match)
-Start of the string
Example: "^cat" “cat” “catsup” “concatenate” (no match) “kitty-cat” (no match)
$
-End of the string
Example: "cat$" “cat” “catsup” (no match) “concatenate” (no match) “kitty-cat”
Escape Character: escapes the next character to be treated as a literal character
Example: /$
“$”
( … )
-Capture Group: identifies matches that should be extracted
Example: “c(at)”
“cat” (“at” is captured)
“bat” (no match)
(?: … )
-Non-Capturing Group: identifies matches that should not be extracted
Example: “c(?:at)”
“cat” (“c” is captured)
“bat” (no match)
(?! … )
-Negative Lookahead Group: identifies expressions that negate earlier matches
Example: “cat(?! burglar)”
“cat”
“cats”
“cat burglar” (no match)
\D
-Matches a non-digit
“1” (no match) “A” “_” “!” “ ”
\w
-Matches a word character (letter, digit, or underscore)
“1” “A” “_” “!” (no match) “ ” (no match)
\W
-Matches any non-word characters
“1” (no match) “A” (no match) “_” (no match) “!” “ ”
\s
-Matches any whitespace character, such as spaces and tabs
“1” (no match) “A” (no match) “_” (no match) “!” (no match) “ ”
\S
-Matches any non-whitespace character
“1” “A” “_” “!” “ ” (no match)
[…]
-Character Set:
+Matches any characters inside the brackets
+Can specify ranges of characters as well
Example set: "[A-C]" “A” “B” “C” “D” (no match) “E” (no match)
[^…]
-Negative Character Set:
+Matches anything NOT inside the brackets
Example set:"[^C-E]" “A” “B” “C” (no match) “D” (no match) “E” (no match)
.
-Wildcard: matches any character (except a newline)
“1” “A” “_” “!” “ ”
*
-Matches 0 or more times
Example: "ca*t" “ct” “cat” “caat” “caaat” “caaaat”
+
-Matches 1 or more times
Example: "ca+t" “ct” (no match) “cat” “caat” “caaat” “caaaat”
?
-Matches 0 or 1 times
Example: "ca?t" “ct” “cat” “caat” (no match) “caaat” (no match) “caaaat” (no match)
{#,}
-Matches at least a specific number of times
Example: "ca{2,}t" “ct” (no match) “cat” (no match) “caat” “caaat” “caaaat”
{# , #}
-Matches within a specific range of times
Example: "ca{2,3}t" “ct” (no match) “cat” (no match) “caat” “caaat” “caaaat” (no match)
|
-Alteration: matches either the expression before or the expression after (OR)
Example: “cat|dog”
“cat”
“dog”
“bird” (no match)
-Start of the string
Example: "^cat" “cat” “catsup” “concatenate” (no match) “kitty-cat” (no match)
$
-End of the string
Example: "cat$" “cat” “catsup” (no match) “concatenate” (no match) “kitty-cat”
Escape Character: escapes the next character to be treated as a literal character
Example: /$
“$”
( … )
-Capture Group: identifies matches that should be extracted
Example: “c(at)”
“cat” (“at” is captured)
“bat” (no match)
(?: … )
-Non-Capturing Group: identifies matches that should not be extracted
Example: “c(?:at)”
“cat” (“c” is captured)
“bat” (no match)
(?! … )
-Negative Lookahead Group: identifies expressions that negate earlier matches
Example: “cat(?! burglar)”
“cat”
“cats”
“cat burglar” (no match)