Regular Expressions 2 Flashcards
What is a regular expression?
A regular expression, regex or regexp, is a sequence of characters that define a search pattern.
What does [A-Z] mean?
Any character from A to Z
e.g [0-9] 0,1,2..9
[a-d] a,b,c,d
What does \s mean?
Any whitespace character (tab \t, space, new-line \n)
What does \w mean?
Any alphanumeric character
What does \b mean?
Stands for a word boundary
What does \d mean?
Stands for a digit (= [0-9] )
What does {x,y} do?
{x,y} specifies the number of repeats of a previous item
a{1,3} matches a, aa ,and aaa, but not aaaa
a{1,} means 1 or more a
What does ^[ ] mean?
^ at the beginning [ ] matches all characters specified in the group at the start of a line or given sentence
What does [^ ] mean?
When [^inside brackets], it means “not”.
What does $ do?
$ matches the end of a text
What does ^ do?
^ matches the start of a text
What does . mean?
. (dot) is the wildcard symbol (any letter)
What does ? mean?
? specifies that the previous character is optional
What does + and * mean? And what are they called?
• + matches one or more of the preceding character (or range) • * matches zero or more of the preceding character (or group) • + and * are called (Kleene) closures
What does \D \S \W mean?
\D Any non-digit character, equivalent to [^0-9]
\S Any non-whitespace character, equivalent to [^\t\n\r\f\v]
\W Any non-alphanumeric character, equivalent to [^a-zA-Z0-9_]