Appendix Summary
A regular expression defines a set of one or more strings of characters. A regular expression is said to match any string it defines.
In a regular expression, a special character is one that does not represent itself. Table A-9 lists special characters.
Table A-9. Special characters
Character
|
Meaning
|
.
|
Matches any single character
|
*
|
Matches zero or more occurrences of a match of the preceding character
|
^
|
Forces a match to the beginning of a line
|
$
|
A match to the end of a line
|
\
|
Quotes special characters
|
\<
|
Forces a match to the beginning of a word
|
\>
|
Forces a match to the end of a word |
Table A-10 lists ways of representing character classes and bracketed regular expressions.
Table A-10. Character classes and bracketed regular expressions
Class
|
Defines
|
[xyz]
|
Defines a character class that matches x, y, or z
|
[^xyz]
|
Defines a character class that matches any character except x, y, or z
|
[xz]
|
Defines a character class that matches any character x through z inclusive
|
\(xyz\)
|
Matches what xyz matches (a bracketed regular expression) |
In addition to the preceding special characters and strings (excluding quoted parentheses, except in vim), the characters in Table A-11 are special within full, or extended, regular expressions.
Table A-11. Extended regular expressions
Expression
|
Matches
|
+
|
Matches one or more occurrences of the preceding character
|
?
|
Matches zero or one occurrence of the preceding character
|
(xyz)+
|
Matches one or more occurrences of what xyz matches
|
(xyz)?
|
Matches zero or one occurrence of what xyz matches
|
(xyz)*
|
Matches zero or more occurrences of what xyz matches
|
xyz|abc
|
Matches either what xyz or what abc matches (use \| in vim)
|
(xy|ab)c
|
Matches either what xyc or what abc matches (use \| in vim) |
Table A-12 lists characters that are special within a replacement string in sed and vim.
Table A-12. Replacement strings
String
|
Represents
|
&
|
Represents what the regular expression (search string) matched
|
\n
|
A quoted number, n, represents what the nth bracketed regular expression in the search string matched |
|