Sublime Forum

What does '\G' mean in syntax definition?

#1

Does the ‘\G’ anchor have any meaning in syntax definition’s regex? I think I’ve seen it in some syntax files, but can’t find any word on it in the docs.

0 Likes

#2

That is a oniguruma-specific anchor: https://github.com/kkos/oniguruma/blob/6a13239e0c5b55e1c55c1f9d27429343407383e4/doc/RE.

Generally this should not be necessary if you are writing a syntax that only uses regular expressions compatible with Sublime Text’s custom regexes engine. You can use the Syntax Tests build system to test regex compatibility.

Oniguruma has a need for it to control backtracking behavior and prevent certain instance of catastrophic backtracking.

0 Likes

#3

Ok, alright, thanks. I thought for a moment it could be used in Sublime to anchor the search to the end of the last match. Is there any way to manage that within the means of the sublime-syntax system?

0 Likes

#4

What are you trying to accomplish? Sublime’s regex engine will automatically match the first pattern that matches the first char after the last match. Thus usually it is just a means to pushing into the appropriate context with a suitably-ordered list of matches.

1 Like

#5

In my struggle with this task for a moment I though such capability would have help simplifying some non-essential details.

0 Likes