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
.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityAccording 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
.
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].
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.
C-h f re-search-forward
is very clear about this being dependent uponcase-fold-search
, and I'm confident that the manual does not say any differently. – phils Oct 14 '18 at 12:09