Node:Regexp Search, Next:, Previous:Loops & Recursion, Up:Top



12 Regular Expression Searches

Regular expression searches are used extensively in GNU Emacs. The two functions, forward-sentence and forward-paragraph, illustrate these searches well. They use regular expressions to find where to move point. The phrase `regular expression' is often written as `regexp'.

Regular expression searches are described in Regexp Search, as well as in Regular Expressions. In writing this chapter, I am presuming that you have at least a mild acquaintance with them. The major point to remember is that regular expressions permit you to search for patterns as well as for literal strings of characters. For example, the code in forward-sentence searches for the pattern of possible characters that could mark the end of a sentence, and moves point to that spot.

Before looking at the code for the forward-sentence function, it is worth considering what the pattern that marks the end of a sentence must be. The pattern is discussed in the next section; following that is a description of the regular expression search function, re-search-forward. The forward-sentence function is described in the section following. Finally, the forward-paragraph function is described in the last section of this chapter. forward-paragraph is a complex function that introduces several new features.