Pcregrep 包含文件扩展名错误

Pcregrep include file extension bug

我正在使用 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$'