I was recently learning about Linux regular expressions, and I found that on my computer the less
program’s regex searching behavior is quite weird when being called from man
. For example, if I run man ls
and use /-a
for searching, I can find the “-a” and part of the “–all” option on the first page of the manual. However, by just adding a space in the search pattern (i.e., using / -a
for searching), less
shows to me “Pattern not found”, which should not happen. However, I then created a text file in which a line begins with spaces and then follows “-abc”, and use less
to open the file. This time, / -a
successfully matched the begining of “-abc”. I am running Fedora 35 with less 590 and man 2.9.4, which should be the latest version. It would be great if anyone can reproduce my problem.
I have checked my environment variables and both $PAGER
and $MANOPT
are not set, so man
should be in default settings.
By the way, when I run less --version
, I see that less in Fedora uses POSIX regular expressions, while the less program on my Debian WSL 2 virtual machine uses GNU regular expressions. Are these two different, and if so what are the differences? Also, man ls
on my Debian virtual machine does not have this weird behavior.