Autohotkey Regex Lookbehind 断言

Autohotkey Regex Lookbehind Assertion

在我的脚本中 'matchfile 是带或不带扩展名的文件名。

在我下面的文字中,可能有也可能没有[AnyText],括号内的文字可以是任何字母数字字符。

如何匹配:

some text
\includescore{something}
\includescore{something.ext}
%\includescore{doNOT.match}
\includescore[AnyText]{something}
\includescore[AnyText]{something.ext}
more text

到目前为止我有这个:

regexmatch(searchthis, "mi)(?<=(?<!%)\includescore\{|(?<!%)\includescore\[\w\]\{)[\w\s\.\+'#-]+\.?[\w\s\.\+'#-]+(?=.*\})", matchfile)

但是那只能匹配:

\includescore{something}
\includescore{something.extension}
\includescore[a]{something}

如果该行以 % 开头,我不想匹配。

我的第一个想法是使用 w+,但 Autohotkey 不允许未量化的回顾。

其实我连方括号的匹配都不关心。我只需要匹配 \includescorematchfile 和大括号。

是否有其他方法可以做到这一点,或者我是否需要进行多次正则表达式调用?

或许,这就是你想要的:

mi)^(?:(?<!%)\includescore(?:\[\w*\])?(?:\{[\w.]*\})|.*matchfile(?:\.\w*)?)

\includescore(?:\[\w*\])?(?:\{[\w.]*\}) 将捕获所有具有可选 [AnyText] 和强制性 {something} 的包含分数。

如果 'matchfile' 不在行首,我添加了 .*,可选的扩展名将被捕获 (?:\.\w*)?)

我用这个工作了:

;Fetch the uncommented inclusion line
regexmatch(searchthis, "mi)(?<=(?<!%)\includescore).*?{(.*?)}", matchfile)

;Now pull out the bracketed item
regexmatch(matchinclusion, "i)(?:\[.*\])", includeparam)        ;get the parameter

;now pull out the filename with/without the extension
regexmatch(matchinclusion, "i)(?<={)(.*)(?=})", inclusionfile)  ;get the tex name

它在所有方面都匹配,并排除了用 %.

注释的行

在 Autohotkey 中,它匹配每个实例,并且只 returns 第一个。