Where can I find reference for less regex search patterns?

I want to search file with less using \d to find digits, but it does not seem to understand this wildcard. I tried to find a reference for less regex patterns, but could not find anything, not on man pages and not on the Internet.


3 Answers 3


less's man page says:

          Search forward in the file for the N-th line containing
          the pattern.  N defaults to 1.  The pattern is a regular
          expression, as recognized by the regular expression library
          supplied by your system.

so the accepted syntax may depend on your system. Off-hand, it seems to accept extended regular expressions on my Debian system, see regex(7), and Why does my regular expression work in X but not in Y?

\d is from Perl, and isn't supported by all regex engines. Use [0-9] or [[:digit:]] to match digits. (Their exact behaviour may depend on the locale.)

  • 1
    > as recognized by the regular expression library supplied by your system. < so… any way to direct less to libpcre? Jan 28, 2021 at 20:54
  • I have Debian 10 according to lsb_release. If I run less on a file that contains a's and e's, and use the command /a|e/, less only highlights the a's. If I enter the command /a\|e/ I get pattern not found. This tends to support that less is accepting the basic syntax, according to man re_format. If I made a mistake in trying to invoke extended syntax, please let me know. Jun 9 at 22:51
  • @cardiffspaceman, did you put the trailing / there? I don't think less expects that, so it'll look for the string e/ as the other alternative. It has to be extended regexes, since BRE doesn't have the alternation, and in BRE, a|e would look for that literal string
    – ilkkachu
    Jun 9 at 23:02
  • @likkachu leaving off the trailing / does make the command work as expected, extended RE. Jun 15 at 1:09

The expressions supported by less are documented in the re_format(7) manual (man 7 re_format). That manual describes both the extended regular expressions and the basic regular expressions available on your system. The less utility understands extended regular expressions.

To match a digit, you would use [0-9] or [[:digit:]] (there's a slight difference as the former depends on the current locale). The \d pattern is a Perl-like regular expression (PCRE), not supported by less.


Less can use multiple regex engines. It depends on compile option. Please refer to this: https://stackoverflow.com/questions/14698364/what-is-the-regular-expression-library-supplied-by-my-system

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.