Topic 9 - Regular Expressions Flashcards
matches any single character except newline
.
matches zero or more occurrence of the previous single character
*
escape character
\
matches the beginning of a line
matches the end of a line
$
do not use $ with double quotes - problems with the shell
-matches a single character in a set or range of characters
[..]
Eg: a[bc]
matches a string that has a followed by b or c
- combine […] with * to match repeated sets
[^…]
matches the complement of whats inside the square brackets
Eg: [^a-zA-Z] will match a string that does not have any of the English letters
\less-than-sign
matches the BEGINNING of a regular expression word
>
matches the END of a regex word
(….)
\n
- remembers a portion of regular expression
- recalls the remembered portion where n is a digit from 1 to 9
X{m}
X{m,n}
- matches exactly m repeated of the one character regular expression X
- matches m to n repeats of X
X{m,}
matches m or more repeats of X
matches simply m or fewer repeats of X
X{,m}
matches a string that has a $ before one digit
$\d
matches any string that starts with The
^The
matches a string that ends with end
end$
Matches lines which only have the words:
The end
^The end$
matches a string that has ab followed by one or more c
abc+
matches a string that has ab followed by zero or more c
abc*
matches a string that has ab followed by zero or one c
abc?
matches a string that has ab followed by 2 c
ie: abcc
abc{2}
What are the quantifier operators?
- ,+ ,? and {}
matches a string that has ab followed by 2 or more c
abc{2,}
matches a string that has ab followed by 2 up to 5 c
abc{2,5}