【发布时间】:2016-05-20 21:00:03
【问题描述】:
上下文,gedit 中的语法高亮显示。
问题:我想捕获特定区域内的所有事件。玩具示例:
other text here $5
keyword1 -> (( ran$3dom$6t:,ext$9 ))
keyword1 -> (( ran$2dom$4t:,ext$6 ))
other text here $7
我想在keyword1 的(( text )) 中捕获(突出显示)所有$0-9(个位数)的事件。 (这里是$3、$6、$9、$2、$4、$6 但不是$5和$7)。这归结为:如何在更大的比赛中重复捕获一个组?
我可以抓取所有可能出现组的文本:(?<=keyword1)|\(\(.*\)\)(gedit 默认使用 \g)
<context id="keyword1" style-ref="argument">
<match>(?<=keyword1)|\(\(.*\)\)</match>
</context>
我发现了这个相关问题:How can I write a regex to repeatedly capture group within a larger match? 但该答案在后视中使用了无限重复,不幸的是,gedit 不支持(据我所知)。有什么建议吗?
【问题讨论】:
-
如果 gedit 支持 PCRE,您可以使用基于 \G 的正则表达式。