I keep seeing this regex in language-grammars which allow editors to highlight syntax.
I know what the regex is trying to convey:
(?!\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
Here's the snippet which caught my attention:
console
# 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'
}
]
}
]
The above snippet is from atom/language-javascript package.
From what I've understood by browsing various text-mate forums is that for highlighting, the editor would start at begin
and go on till the end
regex. Here it starts by matching the console
keyword and then goes on till it matches the end
regex, which I'm not able to understand, as in, where would it stop?
Could somebody explain it?