Say I want to match the a character "h a" or "f a". So capture all the a that are preceded by an h or an f.

I tried the following :

1) \(h\|f\) \\(a\\)

but it doesn't work. the problem appears to be with the the OR group, if I do

2) h \\(a\\) the a in the string h a is captured.

Does anyone know how to fix my first expression?

1 Answer 1


There's a clear difference between the group that is working:


and the group that is not working:


You need to double your backslashes in the non-working group (and for \\| as well).

In elisp backslashes are special to both the double-quoted string syntax and the regexp syntax, so when regexps are represented as double-quoted strings you need to double-escape the backslashes which are intended for the regular expression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.