0

I am trying to match a regex using this code

(search-backward-regexp "\n[\t\n ]*?\n" nil "NOERROR" 1)

search-backward-regexp documenation says

Set point to the beginning of the match, and return point.

How can I set point to end of match?

3

After running the search, go to match-end. (Included fix from Dan's answer)

(when (search-backward-regexp "\n[\t\n ]*\n" nil 'noerror)
  (goto-char (match-end 0)))

From the docstring of search-backward-regexp:

See also the functions match-beginning, match-end, match-string, and replace-match.

  • Are see also functions generated programmatically or documented manually? – ChillarAnand Aug 25 '15 at 5:26
  • @ChillarAnand they are manually written in the docstring. – Malabarba Aug 25 '15 at 10:42
2

This is a minor modification to @Malabarba's answer. It only goes to match-end if your search succeeds. Otherwise, the goto-char will send you off to wherever you had a successful match on a prior regexp search (whether you initiated it, or some other function used it under the hood), which could lead to astonishing jumps.

(when (search-backward-regexp "\n[\t\n ]*\n" nil 'noerror)
  (goto-char (match-end 0)))

Probably best to wrap this in a function.

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.