Sams Teach Yourself Emacs in 24 Hours |
|||||||||||||||||
Hour 9: Regular Expressions |
|||||||||||||||||
|
In the shell (also know as the commands prompt) you often use wildcards (also known as patterns). Wildcards are a way of specifying several files in an easy way. Examples of this include
*--Lists all files. You can, for example, execute the command rm *.to erase all your files. (No, don't try it!)
*.el--Lists all files ending in .el.
Patterns have some limitations, which made the people behind Emacs choose to use the more-powerful regular expressions. These limitations are not that important in the shell, but they are when you search for text in a buffer, for example. Things which you can't do with patterns but you can do with regular expressions include
Searching for the phrase this word , where the space in between the two words can be a number of ordinary spaces, tabs, or newlines.
Searching for the word search somewhere on the line, but not the word research.
In Hours 7, "Searching for Text in a Buffer," and 8, "Searching for Text in Multiple Files," you already saw examples where Emacs wants a regular expression and, believe me, you will see numerous examples in the hours to come. In most cases, however, you only need a very limited subset of the power of regular expressions. Therefore Table 9.1 lists some expressions written both as patterns and as regular expressions. This should give you enough information to read the hours to come.
In regular expressions, the following characters are special: $, ^, ., *, +, ?, [, ], and \. To include any of these (without their special meanings) in a regular expression, prepend them with a backslash. Thus, to insert the text abc\tdef? as an ordinary string in a regular expression, use the text abc\\tdef\?.
All the regular expression operators are listed in Table 9.2. You will learn more about these operators throughout this hour. So keep reading.
Sams Teach Yourself Emacs in 24 Hours |
|||||||||||||||||
Hour 9: Regular Expressions |
|||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.