Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex working on regex101 but not in Vscode snippet

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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 / and lib
  • ([^\\\\\\/]+) – Group 1 ($1): one or more chars other than \ and /
  • [\\\\\\/] – a / or \.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading