regex - 什么是 'the regular expression library supplied by [my] system' ?

标签 regex linux gnu

GNU 的 less 实用程序的 man 页面说明了以下关于搜索的内容:

/pattern
    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.

我在各种系统上都使用 less:我的个人 Ubuntu 笔记本电脑、我的 CentOS 云服务器、在工作中使用 Cygwin 等等。我一直想做一些事情,比如负面前瞻和其他幻想东西,但我不知道要使用什么正则表达式语法。我怎么知道?

最佳答案

它是一个编译时参数。 less 的 ./configure 脚本知道 with-regex=LIB 参数。

这是来自上游包的 README 的引用:

--with-regex=lib

     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).

因此,您需要知道“./configured”有多少。我在 Debian/Ubuntu 上对此进行了调查。他们使用 POSIX 正则表达式库。

我仍在寻找一种通过脚本动态检测它的方法...:)


更新:到目前为止,我所做的唯一一件事就是检测 less 是否使用 pcre 正则表达式。如果 less 是使用 --with-regex=pcre 配置的,它会链接到 libpcre.so 共享库:

#!/bin/bash

# ldd prints out the shared libraries a binary is linked to.
# This can be used to check if less is linked against libpcre
if ldd "$(which less)" | grep 'libpcre\.so' ; then   
    echo "less uses pcre regex syntax"
else 
    echo "less uses non pcre regex syntax"
    # ... more checks should follow. currently trying to find a way
fi

关于regex - 什么是 'the regular expression library supplied by [my] system' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14698364/

相关文章:

licensing - GNU/GPL 许可证和图像

javascript - 如何返回每个匹配项的完整单词,而不仅仅是使用 match 匹配的单词部分?

sql-server - SQL Server,在 LIKE 语句中组合 % 和 [] 通配符

linux - 在 linux 终端中查找并删除文件名中包含相同字符串的文件

linux - 重定向域但保留原始 url

assembly - ELF 格式的可重定位符号(汇编语言)

regex - 我怎样才能让 sed 只匹配第一次出现的字符?

php - 如何实现我的算法文本更正以替换文本中的单词?

linux - 理解ipc通信的linux管道生命线

arm - 未配置STM32 WWDG中断触发