Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the OR operator in emacs regexps?

Tags:

regex

emacs

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 "False". I get the following message:

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

What am I doing wrong?

like image 599
Samuel Danielson Avatar asked Dec 14 '10 19:12

Samuel Danielson


People also ask

Is a special character in regex?

Special Regex Characters: These characters have special meaning in regex (to be discussed below): . , + , * , ? , ^ , $ , ( , ) , [ , ] , { , } , | , \ . Escape Sequences (\char): To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ).

How do I add a new line in regex?

"\n" matches a newline character.


1 Answers

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

like image 83
Victor Deryagin Avatar answered Sep 19 '22 14:09

Victor Deryagin