[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
20.7 Regular Expression Example
Here is a complicated regexp—a simplified version of the regexp that Emacs uses, by default, to recognize the end of a sentence together with any whitespace that follows. We show its Lisp syntax to distinguish the spaces from the tab characters. In Lisp syntax, the string constant begins and ends with a double-quote. ‘\"’ stands for a double-quote as part of the regexp, ‘\\’ for a backslash as part of the regexp, ‘\t’ for a tab, and ‘\n’ for a newline.
"[.?!][]\"')]*\\($\\| $\\|\t\\| \\)[ \t\n]*" |
This contains four parts in succession: a character set matching period, ‘?’, or ‘!’; a character set matching close-brackets, quotes, or parentheses, repeated zero or more times; a set of alternatives within backslash-parentheses that matches either end-of-line, a space at the end of a line, a tab, or two spaces; and a character set matching whitespace characters, repeated any number of times.
To enter the same regexp in incremental search, you would type <TAB> to enter a tab, and C-j to enter a newline. You would also type single backslashes as themselves, instead of doubling them for Lisp syntax. In commands that use ordinary minibuffer input to read a regexp, you would quote the C-j by preceding it with a C-q to prevent C-j from exiting the minibuffer.