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

人走茶凉 提交于 2019-12-21 03:52:29

问题


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

回答1:


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\\.*$



回答2:


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.




回答3:


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

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



来源:https://stackoverflow.com/questions/19967583/regular-expression-to-match-folder-name-with-productivity-power-tools-color-codi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!