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
Name
  • 7,689
  • 4
  • 38
  • 84

1 Answers1

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.

Mark Karpov
  • 4,893
  • 1
  • 24
  • 53