gpt4 book ai didi

regex - Pcregrep 包含文件扩展名错误

转载 作者:太空宇宙 更新时间:2023-11-04 10:22:51 24 4
gpt4 key购买 nike

我正在使用 pcregrep 搜索多行模式,我只希望 pcregrep 搜索具有特定文件扩展名的文件,即

pcregrep -Mrl --include=*.sv -e '<my_multi-line_pattern>' /path/to/search

但是,这会引发错误:pcregrep: Error in 'include' regex at offset 0: nothing to repeat .

我试过转义和双重转义 *无济于事。这种语法似乎适用于 grep

grep -rl --include=*.sv '<my_single-line_pattern>' /path/to/search

非常感谢任何帮助或提示。

编辑:示例多行模式:'(?s)^\salu.*\.opa_i('应该匹配

alu u_alu(
...
.opa_i(opa),
.opb_i(opb),
...
)

最佳答案

这是pcregrep's docs说一下 --include(强调我的):

--include=pattern If any --include patterns are specified, the only files that are processed are those that match one of the patterns (and do not match an --exclude pattern). This option does not affect directories, but it applies to all files, whether listed on the command line, obtained from --file-list, or by scanning a directory. The pattern is a PCRE regular expression, and is matched against the final component of the file name, not the entire path. The -F, -w, and -x options do not apply to this pattern. The option may be given any number of times. If a file name matches both an --include and an --exclude pattern, it is excluded. There is no short form for this option.

在正则表达式开头的 * 当然有效。
现在您可以理解错误消息了:)

解决方案:--include='.*\.sv$' 或者只是 --include='\.sv$'

关于regex - Pcregrep 包含文件扩展名错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43123536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com