简体   繁体   中英

What is the OR operator in emacs regexps?

The manual says to use '\\|', as in a\\|b matches a or b. But when I use it with regexp builder or align-regexp eg with, "True\\|False", it doesn't recognize "True" or "False". I get the following message:

Wrong argument type: integer-or-marker-p, nil

What am I doing wrong?

Use double escape: \\\\|

A Few Additional Notes:

Emacs has 2 escaping styles, one in EmacsLisp the other when used in commands,
ie. from the Mx prompt ( rgrep , occur , …)

In EmacsLisp, use the double backslash \\\\|

From Mx … use a single backslash \\|

… As a side note, when writing embedded EmacsLisp, for example in yasnippet dynamic expansions, you have to use a quadruple backslash: \\\\\\\\| (to escape the double backslashes.)

Always avoid this (if possible), for example in yasnippet you can provide mode related emacslisp, without the additional escaping, via a .yas-setup.el

For further details, see the discussion of '\\' and strings in the elisp manual section 34.3.1.1 "Special Characters in Regular Expressions"

M-: (info "(elisp) Regexp Special") RET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM