What is the OR operator in emacs regexps?

后端 未结 2 556
走了就别回头了
走了就别回头了 2021-02-15 07:57

The manual says to use \'\\|\', as in a\\|b matches a or b. But when I use it with regexp builder or align-regexp e.g. with, \"True\\|False\", it doesn\'t recognize \"True\" or

相关标签:
2条回答
  • 2021-02-15 08:29

    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

    0 讨论(0)
  • 2021-02-15 08:49

    Use double escape: \\|

    A Few Additional Notes:

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

    In EmacsLisp, use the double backslash \\|

    From M-x … 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

    0 讨论(0)
提交回复
热议问题