I want to match a certain string (not even a regex!) at point. re-search-forward skips characters after the point.

With char-after it is possible to build a framework for matching a string at point. I hope there is an idiomatic way to match a string at point.

UPDATE alternatively I can search-forward and if:

old point - new point != string length

I miss match...

Or set bound to string length:

(search-forward str (+ (point) (length str)) nil)

Pity that search-forward moves pointer...

  • 1
    "(not even regex!)" directly conflicts with your title. Do you want to match a regexp or not?
    – phils
    Apr 19, 2019 at 20:28
  • If you want to match a word you could use thing-at-point to get the word and then compare with string=.
    – JeanPierre
    Apr 20, 2019 at 1:37
  • "Pity that search-forward moves pointer..." - that's why save-excursion exists.
    – NickD
    Jul 4, 2023 at 0:48

2 Answers 2


Are you looking to do this from lisp code? If so, you can use looking-at:

(looking-at REGEXP)

Return t if text after point matches regular expression REGEXP. This function modifies the match data that ‘match-beginning’, ‘match-end’ and ‘match-data’ access; save and restore the match data if you want to preserve them.

For example, if point is right after the parenthesis in:

(looking-at "abc")abc

running C-x C-e will return t. However, doing the same if there's an x before abc will return nil:

(looking-at "abc")xabc
  • 1
    I think this is what OP is looking for. And if there are regexp-special chars in the string to match, and he doesn't wants them matched literally, then (looking-at (regexp-quote "the-string-to-match")). And there is also looking-at-p. (Feel free to incorporate any of this into your answer if you like.)
    – Drew
    Apr 19, 2019 at 21:52

The regular expression to match point in emacs is \=. Try e.g. (search-forward-regexp "\\=blah").

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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