I am struggling with a regex that works fine on regex101: https://regex101.com/r/Hhj2l9/1, but not in a vscode snippet for html.
From the following string: C:\folder0\folder1\folder2\libtest\folder3\folder4\folder5
I get the following results on regex101: libtest/libfolder3/libfolder4/folder5
, which is what I want.
In my snippet:
lib${TM_DIRECTORY/(?:.*lib)?([^\\\\.*]*)\\\\/$1\\//g}
The result below in the html:
lib${TM_DIRECTORY/(?:.*lib)?([^\.*]*)\/\//g}
Has anyone an idea on how to make it work in a vscode snippet? Thanks a lot in advance.
CodePudding user response:
You can use
"${TM_DIRECTORY/(?:.*[\\\\\\/]lib)?([^\\\\\\/] )[\\\\\\/]/lib$1\\//g}"
Here,
(?:.*[\\\/]lib)?
- matches an optional occurrence of any zero or more chars other than line break chars as many as possible, and then\
or/
andlib
([^\\\\\\/] )
- Group 1 ($1
): one or more chars other than\
and/
[\\\\\\/]
- a/
or\
.