Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression to match folder name with Productivity Power Tools Color Coding

I would like to configure a RexEx to match any folder (parent or child) of a file path of any open file. So if any folder in the file path contains the name of the open file, the color coding of the tab is set based on the RegEx match.

For example: websiteRoot/Content/MyName1/site.css = green colored tab when file opened

websiteRoot/Content/MyName2/site.css = orange colored tab when file opened

websiste/Shared/MasterPages/MyName1/main.master = green colored tab when file opened

websiste/Shared/MasterPages/MyName2/main.master = orange colored tab when file opened

I have tried: .*MyName1?$ but this is only looking at the file name I believe.

Also tried .*//MyName1//?$ and I thought this next one would do the trick if Regex for this extension directly matches on the open file path: ^.*\\MyName1

More promising regex with no success:

.*websiteRootPath.*MyName1|myname1|myName1

And if Power Productivity Tools works off a relative path for the open file:

.*MyName1|myname1|myName1
like image 643
Brian Ogden Avatar asked Nov 14 '13 01:11

Brian Ogden


People also ask

How do you write regex in Visual Studio code search?

Vscode has a nice feature when using the search tool, it can search using regular expressions. You can click cmd+f (on a Mac, or ctrl+f on windows) to open the search tool, and then click cmd+option+r to enable regex search. Using this, you can find duplicate consecutive words easily in any document.

How do you match exact strings?

We can use the JavaScript string instance's match method to search for a string that matches the given pattern. to call match with a regex that matches the exact word. ^ is the delimiter for the start of the word. And $ is the delimiter for the end of the word.

How do I find a specific text in regex?

To use regular expressions, open either the Find pane or the Replace pane and select the Use check box. When you next click Find Next, the search string is evaluated as a regular expression. When a regular expression contains characters, it usually means that the text being searched must match those characters.

What regex does VS code use?

VS Code does support regular expression searches, however, backreferences and lookaround aren't supported by default. But you can enable these with the setting search. usePCRE2. This configures ripgrep to use the PCRE2 regex engine.


2 Answers

I was working on this in VS 2017, you have to enable the option to match the path of the document.

Use full document path for regular expression matching

You need to have some background about regular expressions, here are some examples:

.*folder\\.*$
.*folder\.detail\\subfolder\\.*$
.*folder\\subfolder\\subfolder\\.*$

You can test your own regex here

like image 191
ramons03 Avatar answered Sep 28 '22 03:09

ramons03


You have to check "Use full document path for regular expression matching" under

Options -> Productivity Power Tools -> Advanced

After that, you can use the RegEx's like

.*app\\model\\.*$
.*app\\view\\.*$
.*app\\controller\\.*$
like image 38
Martin Möhnen Avatar answered Sep 28 '22 03:09

Martin Möhnen