Reputation: 97
completely stumped on this one;
trying to recognize this: x content end_x
I'm trying to get sublime to recognize for some specific functions for a programming language - for example, I'm trying to get the first bit of the function to be recognized (which could be any string x) then have the full function (including any characters). The only defining feature of the function is the closing statement "end_", followed by the same string x from the opening statement.
I'm just wondering if this is possible? If so, how?
I should probably add - I'd really only want to highlight x and end_x, not particularly the content content
Upvotes: 1
Views: 363
Reputation: 41838
Use this regex:
(?s)(\S+) .*? end_\1
See the sample matches in the regex demo.
Explanation
(?s)
activates DOTALL
mode, allowing the dot to match across lines(\S+)
capture any chars that are not white-space chars.*?
lazily matches up to...end_
literal chars\1
the content that was matched by Group 1Upvotes: 1