All the documentation I can find says this should be returning the index of the first of the three x's but instead it returns nil:

(string-match "x\{3\}" "string with 3 x's repeating: xxx")

enter image description here

update: I had to escape the backslashes:

(string-match "x\\{3\\}" "string with 3 x's repeating: xxx")
  • Need another backslash to escape.
    – Dan
    Mar 18 '16 at 1:38
  • 2
    Please write up the answer as an answer, and accept it. (It's fine to accept your own answer.)
    – Drew
    Mar 18 '16 at 4:43

Backslashes need to be escaped in strings:

(string-match "x\\{3\\}" "string with 3 x's repeating: xxx")

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.