Make pattern end not capture


#1

Hello friends

I’m wanting to make a pattern end without capturing (I think that’s the correct word) the end value.

In my case, here is my file:

@yaml
yaml here

@python
python here

I wish to have a yaml-formatted block in the beginning of an @yaml, then end when another @something is found. But the only way I know results in the @something not being captured as another start, which it should be. Here is my current grammar patterns:

patterns: [
  {
    begin: '^@yaml'
    end: '@'
    patterns: [{ include: 'source.yaml' }]
  }
  {
    begin: '^@python'
    end: '^@+.(\n|\r)'
    patterns: [{ include: 'source.python' }]
  }
]

Any thoughts? Is this possible?


#2

I made a typo above. This is the correct pattern I currently have:

patterns: [

{
begin: ‘^@yaml’
end: ‘^@+.(\n|\r)’
patterns: [{ include: ‘source.yaml’ }]
}
{
begin: ‘^@python’
end: ‘^@+.(\n|\r)’
patterns: [{ include: ‘source.python’ }]
}
]


#3

You can use regex look ahead to not capture the ending


#4

THIS WORKED!!

end: '(?=^@+.)'