Search code examples
regexvim-syntax-highlighting

Is it possible to match string at the beginning of line, but only capture the end with regex?


I have text that is something like this:

[G&]120948103471390857102349871[002]
[A&]512903451029349012390409232[002]
[2&]512903451029349012390409232[002]

I would like to match only the [002] of the first line that begins with [G&], but nothing else.

It is to be used on "syntax match" for vim syntax highlighting.


Solution

  • After googling longer I discovered that vim regex has a different lookahead/lookbehind.

    Here it is:

    \(G&.*\)\@<=\(\[\d\d\d\]$\)