REGEX Flashcards
How do you specify a unique character?
The simplest way is to add in the character itself to the REGEX.
i.e. a for ‘a’, D for ‘D’, and 3 for ‘3’.
What if you wanted a or b or c, for a specific character index?
bracket notation [ ]
[abc] would match only “a” or “b” or “c”.
What does \d match?
\d matches to ANY digit.
What does \D match?
\D matches with any NON-digit.
What is the REGEX notation for any character?
the period . is the marker for a wild card in regex
to notate a period it must be .
What does \w match?
\w matches to any Alphanumeric character.
What does \W match?
\W matches to any NON-alphanumeric character
How do you express not “x”, nor “y”, nor “z” ?
[^xyz]
the index cannot have x nor y nor z.
How would you match a range of characters?
With a dash -
for example to match capitalized names:
[A-Z][a-z] would match an uppercase character followed by a lowercase character.
How do you specify repetitions?
with curly brackets and a comma.
{ , }
z{3, 5} would match zzz, zzzz, or zzzzz.
How can you express zero or more repetition?
with the * character
aa* would match “”, “aa”, or “aaaa”.
How can you express one or more repetitions?
with the + character
bb+ would match “bb”, “bbbbbb”, but not “”.
How can you denote a character is option?
Follow the character with a ‘?’ to denote it is optional.
ab?c can match ac and abc.
How can you match any whitespace?
with the \s expression.
What does \S match to?
Any NON-whitespace