
\< \> start/end of word (faulty rendering: backslash + less-than and backslash + greater-than) \_ start/end of symbol \ prevents interpretation of following special char ? previous character or group, repeated 0 or 1 time + previous character or group, repeated 1 or more time

* previous character or group, repeated 0 or more time

Many characters are special when they follow a backslash – see below. Regular Expression Syntax Regexp Syntax BasicsĪny character matches itself, except for the list below. There’s also a package xr (available on GNU ELPA) that does the opposite conversion, from string syntax regexps to something more human-readable. When used in InteractiveLispMode, Rx can also be a handy tool to construct regexps. To produce this regexp in string format (which matches C-style multiline and single line comments): \\* \\(?. For example, you can use ‘rx’ like this: (rx (or (and " \*" (*? anything) "*/") (and "//" (*? anything) eol))) However, when writing Lisp code, one can now use the easier to understand Rx Notation, which structures a regular expression as Lisp S-expressions. We use regexps all the time, without knowing it, when we use Emacs.Ĭonventionally, Emacs allows only regular expressions formatted as strings and that is still the case for interactive use, such as ‘M-x’ (command query-replace-regexp). Try ‘C-M-s’ (command isearch-forward-regexp). Regexps are important to Emacs users in many ways, including these: The above regular expression matches “alex” or “alexa”. The question mark, for example, says that the preceding expression (the character “a” in this case) may or may not be present. Some characters have special meanings in a regular expression. The above regular expression matches “alex”. Examples: "alex"Ī plain string is a regular expression that matches the string exactly. It is a pattern that is matched against the text to be searched.

A regular expression (abbreviated “ regexp” or sometimes just “ re”) is a search-string with wildcards – and more.
