Match only first occurrence of pattern


I have a language specification to highlight certain keywords or patterns:

The orange part will be highlighted with the following code:
{ 'match': '\\|\\s(.*)\\s\\|' 'name': 'constant.numeric.gherkin' }

My question is if there exists a solution to match only the first line of the pattern, because I want to highlight this line with a different color (here in the example | n1 | n2 | result |). Basically I would need a match pattern which defines the pattern '\\|\\s(.*)\\s\\|' after the line Examples: (.*) in green and all other lines with this pattern in orange.
And a general question: is there a possibility to define parts to match but not to highlight? Because when I add Examples:... to the match pattern, it will also be highlighted afterwards, or not? I would need to say find this pattern but highlight only a certain part of it.

I’m not sure if my use case is realizable, so thanks for any advice or hint.


You might want to check the language-git package. It highlights the first line differently from subsequent lines.


Thank you for your reply.
The problem is that I have very less experience with CSON and the possibility to match pattern etc… Don’t know what’s possible or not - I read in another discussion that matching a pattern over 2 different lines is (or was) not possible. Therefore I’m searching ideas how to solve this problem.


Matching a pattern that spans two lines does not work, but you can match a pattern on one line and use that match to switch into a different “mode”. This is how matching multi-line comments in C-like languages works.