As I develop an extension in TypeScript for Visual Studio Code, there's a need to extract a specific word (consisting of dots and hyphens) following the '{{>' prefix.
{{>word-test }}
{{> word-test}}
{{> word-test }}
{{> word-test class="class_name"}}
// this should output 'word-test'
// However, it seems that the regex fails in the following scenario
{{> word-test
class="class_name"
}}
// instead of 'word-test', all content in the file is returned
{{> word-test.test }}
// expected result: 'word-test.test'
I utilize the 'getWordRangeAtPosition' feature included in Visual Studio Code, along with a regex pattern as its parameter to retrieve the desired word.
The Issue Encountered
Despite trying various regex patterns, the challenge lies in the failure to retrieve 'word-test' from Visual Studio Code when encountering a line break. Instead, the entire file content is fetched.
Presented below is my latest attempt at a working regex pattern:
/(?<={{>[ \s]{0,1})(.*?)(?=[\n\s\}\}])/
This regex functions flawlessly in online testers but does not yield the intended results within Visual Studio Code itself.
You can test the regex pattern here: