Michael Scheper Michael Scheper - 6 months ago 25
Linux Question

What is 'the regular expression library supplied by [my] system'?

The man page for GNU's less utility says the following about searching:

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.

I use less on all sorts of systems: my personal Ubuntu laptop, my CentOS cloud server, under Cygwin at work, etc. I keep wanting to do things like negative look-aheads and other fancy stuff, but I don't know what regex syntax to use. How do I find out?


It is a compile time parameter. The ./configure script of less knows the with-regex=LIB param.

This is a quote from README of the upstream package:


     Specifies the regular expression library used by less for pattern
     matching.  The default is "auto", which means the configure program 
     finds a regular expression library automatically.  Other values are:
        posix          Use the POSIX-compatible regcomp.
        pcre           Use the PCRE library.
        regcmp         Use the regcmp library.
        re_comp        Use the re_comp library.
        regcomp        Use the V8-compatible regcomp.
        regcomp-local  Use Henry Spencer's V8-compatible regcomp
                       (source is supplied with less).

So you would need to know how less was './configured'. I have investigated this on Debian / Ubuntu. They use the POSIX regex lib.

I'm still searching for a way to detect it dynamically by a script... :)

Update: The only thing I've managed so far was to detect whether less uses pcre regexes or not. If less was configured using --with-regex=pcre it is linked against the libpcre.so shared library:


# ldd prints out the shared library usage of a binary
ldd `which less` | grep libpcre.so

if [ $? = 0 ] ; then
    echo "less uses pcre regex syntax"
    echo "less uses non pcre regex syntax"
    # ... more checks should follow. currently trying to find a way