正则表达式帮助跳过 "*X "行,但不跳过 "**"行。

问题描述 投票:0回答:1

因此,对于PCRE(PHP)正则表达式,我试图从开发团队的主机平台上读取搜索的输出。

我需要解析出文件名,这样我就可以加入到我正在跟踪系统迁移细节的其他列表中。

到目前为止,我的表达式在Regex101.com上。此处 与样本数据.我确信还有更多的效率我可以引入,但现在我希望在走这条路之前满足要求。

以下是参考代码

^(?#
Objective is to capture the first two columns: program name and line number.  This part is easy

I'm able to skip lines with comments and start parsing at the 'QRY' string.

Challenge is I would like to skip lines like this
.*\/\*QRY.*$
and include lines like this [end comment appears before the 'QRY' string]
.*\/\*.*\*\/QRY.*$

Check for comment indicator and skip lines with comments
)(?!.*\/\*.*(?!\*\/)QRY)(?#
)(?#
Program name
)^(?<prgName>.+?)[[:blank:]](?#
QRY clause
)(?:.*QRY\((?<qryName>.*?)\))*(?#
FILE or QRYFILE clause
)(?:.*FILE\(\((?<qryFile01>.*?)\)(?:[[:blank:]]\((?<qryFile02>.*?)\)\))*)*
regex pcre
1个回答
0
投票

试试 '~(?mi)(?:(?:^.*?/\*(?:(?!\*/).)*QRY.*$(*SKIP)(*FAIL))|^(?<prgName>.+?)[[:blank:]](?:.*QRY\((?<qryName>.*?)\))*(?:.*FILE\(\((?<qryFile01>.*?)\)(?:[[:blank:]]\((?<qryFile02>.*?)\)\))*)*)~'

特征

  • 线性 只是,不验证评论
  • 如果在评论开始后的QRY,则SKIP的行开始
  • 通过QRY在注释外的行

演示

© www.soinside.com 2019 - 2024. All rights reserved.