【发布时间】:2016-04-13 06:22:20
【问题描述】:
我经常在语言语法中看到这个正则表达式,它允许编辑器突出显示语法。
我知道正则表达式试图传达什么:
(?!\G) Negative Lookahead - Assert that it is impossible to match the regex below
\G assert position at the end of the previous match or the start of the string for the first match
这是引起我注意的sn-p:
控制台
# console.log(arg1, "arg2", [...])
'begin': '\\bconsole\\b'
'beginCaptures':
'0':
'name': 'entity.name.type.object.console.js'
'end': '(?!\\G)'
'patterns': [
{
'begin': '\\s*(\\.)\\s*(assert|clear|debug|error|info|log|profile|profileEnd|time|timeEnd|warn)\\s*(?=\\()'
'beginCaptures':
'1':
'name': 'meta.delimiter.method.period.js'
'2':
'name': 'support.function.console.js'
'end': '(?<=\\))'
'name': 'meta.method-call.js'
'patterns': [
{
'include': '#arguments'
}
]
}
]
上面的sn-p来自atom/language-javascript包。
根据我通过浏览各种 text-mate 论坛了解到的情况,对于突出显示,编辑器将从 begin 开始,一直到 end 正则表达式。在这里,它首先匹配 console 关键字,然后继续直到它匹配 end 正则表达式,我无法理解,比如它会在哪里停止?
谁能解释一下?
【问题讨论】:
-
我知道前瞻。我在
\G的上下文中问这个问题,特别是语言语法如何解释这个 -
\G- 字符串位置的开始或上一个成功匹配的结束。(?!\G)- 不是可以与\G匹配的同一位置。 -
@WiktorStribiżew 我的问题更关心这将如何影响语法高亮编辑器的最终匹配
-
您对问题进行了标记和构建,听起来确实像是一个骗局。请编辑它,标记
atom。 正则表达式 (?!\G) 有什么作用? 标题使它成为 What does the regex mean 的欺骗。 -
@WiktorStribiżew 我已经编辑了问题的标题和标签
标签: regex grammar atom-editor