Regex Flashcards
beginning of line
end of line
$
Pick one of a list of characters
Use []
[Bb][Uu][Ss][Hh] # this is basically for case insensitive BUSH
Specify range of characters
[0-9][a-zA-Z]
You don’t want a list of characters at the end of line
[^?.]$ will match the lines i like basketballs 6 and 9 dont worry... we all die anyway! Not in Baghdad helicopter under water? hmmm
any single character
use dot “.”
9.11 will match
9-11
9:10
find one of two words
will match the lines
is firewire like usb on none macs?
the global flood makes sense within the context of the bible
(pipe)
flood|fire
find one of two words, lower case or upper case where one of the words specifically must appear at the beginning of the line
^[Gg]ood|[Bb]ad
^([Gg]ood|[Bb]ad)
can have good or bad at the beginining of a line, case doesn’t matter
Search for George W. Bush with the “W” as optional
Gg]eorge( [Ww].)? [Bb]ush
must escape the period by \
Escape special characters like $^.
\
repeating characters
*
.* means repeat any character as many times as you want
p* means repeat p as many times you want
(.*) have parenthesis with any characaters in the middle you want
- and +
The * and + signs are metacharacters used to indicate repetition; * means “any number, including none, of the item” and + means “at least one of the item”
what does [^]
indicates negation,
[^?.]$ means match things that do not end in question mark or period at the end.
turn of grediness of * off
use .*?
*? will find the shortest match