Appendix A. Regular Expressions Regular expressions are used to match strings to patterns, rather than only to literal character strings. The regular expression (sometimes referred to as regex) is a pattern you want to match, such as a pattern that matches all names that begin with B or all phone numbers. Regular expressions are used by many Linux commands and applications that find/select specific text for processing. You can use regular expressions with grep, vi, sed, awk, Perl, PHP, OpenOffice, and many other applications.Regular expressions are combinations of the following:- Literal characters :
Normal characters that have no special meaning. A B is just a B, the second letter of the alphabet. It has no other meaning. - Special characters :
Characters that have special meaning when used in a regular expression. Special characters are not just a letter of the alphabet or a punctuation mark.You may have experience with special characters. For instance, an asterisk (*) is used by Windows, as well as by Linux, to mean any string of characters in a filename. You would use *.txt to find all the text files in a directory or prog* to find all the files that began with prog, regardless of the remainder of the file name.
To create regular expressions, you need to understand what special characters mean and when to use one. This appendix describes the most useful special characters, with examples of their use. |