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

3

11

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
Jehoash answered 14/11, 2013 at 1:2 Comment(8)
I voted the question down because it's basically asking for someone to do the work for you. If you want to make the question better, give specific examples of how it does/doesn't work and the results of running your regex on them. People can then explain why got the results you did and point you in a better direction.Dialectic
Well I don't know where to begin and I certainly have tried researching, reading online documentation and different regex expressions. How would I go about writing a regular expression for to match folders on a Visual Studio Extension with POTENTIALLY proprietary regular expression to work matching path URIs and little available documentation online?Jehoash
didn't I clearly outline how to improve the question without any extra knowledge? give examples of what did/didn't work and the results of the failuresDialectic
My question already states the regex I tried but this is looking at the file name and since there is no documentation on Regular Expressions for the Productivity Power Tools extension and color tabbing I am expecting that word of mouth or perhaps someone that helped build the extension might catch this question and know how to match on a file path.Jehoash
Why does this question get +5 and I get -2?#5753329 Oh the subjective nature of moody codersJehoash
its over two years old...Dialectic
That is the reason that question gets +5?Jehoash
SO standards change over time. Old questions are not always good standards. There have been a lot of "write this code for me" posts recently.Dialectic
W
15

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\\.*$
Whom answered 17/1, 2014 at 11:56 Comment(1)
For the sake of completeness – since I lost some time on this – I'm adding that in this answer app corresponds to the name of the Solution, and not of the Project. Also, Regular expression colors take precedence over project colors has to be ticked (Productivity Power Tools options → Custom Document Well → General, Tab Appearance)Acrobatic
F
3

There are some hidden settings for the document well, described here: Document Well 2010 Plus: Hidden Options

These include a registry setting for that allows the full document path for regular expression match, described as:

By default, only the text that is visible in the tab is used to match regular expression for custom coloring. You can run the following command to instead match the full document path, which gives you greater flexibility

The registry change is this:

reg add HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\DialogPage\Microsoft.DocWellBehavior.GeneralOptions /v UseFullPathForRegEx /t REG_SZ /d True /f

The keys described in the linked document were all in my registry, on a newly built Win8.1 PC with VS2013 (albeit with "12.0" instead of "10.0" in their path as I'm using VS2013). This key at least works as described in my environment, so in the original question the regex .*MyName1.* will select all files with "MyName1" (case insensitive by default) in their path or name.

Favus answered 4/2, 2014 at 16:8 Comment(1)
Great answer, I wanted to color code by assembly and grabbing the full path for regex evaluation is exactly what I needed.Comitia
N
2

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

Nicaragua answered 21/3, 2018 at 23:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.