1

Consider a buffer as below. As explained in the documentation . matches any character but newline. Also \n matches newline. So evaluating (re-search-forward "a\(.\|\n\)*b" nil t) should normally have a match in this document. But it does not.

(As explained in https://emacs.stackexchange.com/a/9549/ when using regular expressions interactively, a\(.\| C-q C-j \) seems to be fine in this situation).

a
b
4

You should escape your regexp string properly:

(re-search-forward "a\\(.\\|\n\\)*b" nil t)

When I place cursor at the beginning of buffer with given contents and evaluate expression (via eval-expression) I get answer 4. That's a match.

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.