Autohotkey Regex Lookbehind Assertion

时间:2015-03-06 22:47:12

标签: regex autohotkey

在我的脚本'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+启动,我不想匹配。

我的第一个想法是使用\includescore,但Autohotkey不允许使用无量化的lookbehind。

实际上,我甚至不关心方括号的匹配。我只需匹配matchfile,{{1}}和大括号。

还有其他方法可以执行此操作,还是需要执行多个正则表达式调用?

2 个答案:

答案 0 :(得分:0)

也许,这就是你想要的:

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

\includescore(?:\[\w*\])?(?:\{[\w.]*\})会捕获所有包含可选[AnyText]和强制性{某些内容}的包含内容。

如果&#39;匹配文件&#39;不在一行的开头,我添加了.*,并且会使用(?:\.\w*)?)

捕获可选扩展名

答案 1 :(得分:0)

我得到了它的工作:

;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中,它匹配每个实例,只返回第一个实例。