Regular Expressions Flashcards
RegEx matches for
/[wW]oodchuck/
Woodchuck
woodchuck
RegEx matches for
/[abc]/
‘a’, ‘b’, or ‘c’
RegEx matches for
/[1234567890]/
any digit
RegEx matches for
/[A-Z]/
An upper case letter
RegEx matches for
/[a-z]/
A lower case letter
RegEx matches for
/[0-9]/
A single digit
RegEx matches for
/[^A-Z]/
Not an upper case letter
RegEx matches for
/[^Ss]/
Neither ‘S’ nor ‘s’
RegEx matches for
/[^.]/
not a period
RegEx matches for
/[e^]/
either ‘e’ or ‘^’
RegEx matches for
/a^b/
the pattern ‘a^b’
RegEx matches for
/woodchucks?/
woodchuck or woodchucks
RegEx matches for
/colou?r/
color or colour
RegEx matches for
/beg.n/
any character between beg and n
RegEx matches for
start of a line
The three uses of the caret ^
- to matcht the start of a line
- to indicate a negation inside of square brackets
- just to mean a caret
RegEx matches for
$
end of line
RegEx matches for
\b
word boundary
RegEx matches for
\B
non-word boundary
Kleene *
“cleany star”
Zero or more occurrences of the immediately previous character or regular expression.
Kleene +
One or more occurrences of the immediately preceding character or regular expression.
Wildcard expression
.
Matches any single character (except a carriage return)
Anchors
Special characters that anchor regular expressions to particular places in a string.
The most common anchors are the caret ^ and the dollar sign $.
^ matches the start of a line.
$ matches the end of a line
\b matches a word boundary
\B matches a non-word boundary
Disjunction
the pipe symbol |
/cat|dog/ matches either cat or dog