0

I want to search for an regular expression with the function re-search-forward

When I tried using the examples from the page here: https://www.emacswiki.org/emacs/RegularExpression#toc1

specifically the regular expression \w\{20,\} used to search for a word with 20 letters or more, I get an error.

Here I am placing my cursor after the closing parenthesis in my Lisp buffer and pressing C-x C-e for evaluating it.

However, when I use the Regexp I-search via, C-M-s it highlights the correct word as expected.

Why is this?

enter image description here enter image description here

smilingbuddha
  • 14,334
  • 33
  • 112
  • 189

1 Answers1

3

This regexp:

\w\{20,\}

is expressed in a double-quoted elisp string like so:

"\\w\\{20,\\}"

Backslashes are special to the double-quoted read syntax for strings as well as being special to regexp syntax; so if a backslash is for the regexp, you need to double it.

phils
  • 71,335
  • 11
  • 153
  • 198
  • Notice also how, in the screenshots in the question, the incorrect singular backslashes are coloured red? That is Emacs (26+) telling you that they are probably a mistake. – phils Nov 23 '18 at 22:29