sábado, 27 de enero de 2018

2 ways to anchor a regex in elisp

This one I just learnt reading a PR in the melpa repo.


Usually we use ^ and $ to match the beginning and end of the line when dealing with regular expressions.

But, the same way we have \A and \z in ruby , in elisp manual: elisp regex backslash explains there is \` and \'  (that would be written \\` and \\' inside your regex string) to anchor the regex match to the beginning and end of the string or buffer. While $ matches end of the line, so "hello$" will match "hello\ngoodbye", while "hello\\'" will not.

No hay comentarios: