The regex scope narrowing by skipping punctuation scopes is too aggressive. It causes errors if the regex begins or ends with a group (or other regex punctuation). It should only skip "punctuation.section.regexp" (begin and end), not "punctuation.definition.group" for example. The problem manifests as an unbalanced group but also occurs more subtly if the group is at both ends of the regex (the grouping disappears from the diagram).
The regex /(foo|bar)/ illustrates the disappearing grouping. And /(foo|bar)$/ illustrates the unbalanced grouping error.
The regex scope narrowing by skipping punctuation scopes is too aggressive. It causes errors if the regex begins or ends with a group (or other regex punctuation). It should only skip "punctuation.section.regexp" (begin and end), not "punctuation.definition.group" for example. The problem manifests as an unbalanced group but also occurs more subtly if the group is at both ends of the regex (the grouping disappears from the diagram).
The regex /(foo|bar)/ illustrates the disappearing grouping. And /(foo|bar)$/ illustrates the unbalanced grouping error.