I'm trying to use a regular expression in the man page of Bash by using less
.
I press / in less
to enter a pattern, and I type z
and press the Enter. I expected it to not match upper-case z
(Z
), but it does.
How do I make it not match Z
? What kind of regular expressions are these that are not case sensitive?
Best Answer
It's explained in the man page for
less
.The default action for REs is to ignore case if there are no uppercase characters present, but to act case-sensitively otherwise.
There are three modes available within
less
:abc
will matchabc
andaBC
, butaBc
will only matchaBc
and notabc
orABC
. This is the default setting.abC
will match onlyabC
and notabc
orABC
.abC
will match any ofabc
,abC
, orABC
.You can toggle case sensitive comparisons with
-I
, and case context sensitive comparisons with-i
.The control can be specified in three ways:
less -I bigfile.txt
.export LESS=-i
and laterless bigfile.txt
.less
itself, for example by startingless bigfile.txt
and then typing-i
.