2

According to the documentation of this function, it should be case sensitive. But when I test it out, the result is case insensitive.

My emacs version is 25.3.2.

  • 1
    According to which documentation? C-h f re-search-forward is very clear about this being dependent upon case-fold-search, and I'm confident that the manual does not say any differently. – phils Oct 14 '18 at 12:09
  • It is my bad in reading documentation. I also read from ergoemacs.org, but somewhat miss the important information. I confirm that your statement is correct. – Cảnh Toàn Nguyễn Oct 14 '18 at 13:50
3

re-search-forward is case insensitive by default as it depends on (as @phils points out in the comment) case-fold-search. You can toggle case sensitivity with: toggle-case-fold-search The following is from ergoemacs.org:

By default, Emacs regex is not case sensitive unless the pattern contains capital letters. That is, dragon will match “dragon” and “Dragon” and “DRAGON” and “draGON”. But Dragon will match only “Dragon”.

Case sensitivity is controlled by the variable case-fold-search. Alt+x toggle-case-fold-search to toggle it. Remember to toggle it back when you are done. Because case-fold-search is also used by isearch and basically all search or find/replace commands.

Do not use [A-z], because that'll match some punctuation chars too. Use [A-Za-z].

3

You can toggle case-sensitivity on the fly during Isearch, using M-c. So just C-M-s M-c will turn on case-sensitivity for the duration of the search (assuming it was turned off globally). You can toggle it back and forth as much as you want during the same search, which can be handy.

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.