Does VS have a customized RegEx?
I wrote an expression to help another gentleman in this thread ensuring it worked using the Expresso free tool. Here is what they wanted searched:
<a href="ProgramInformation.aspx?ID=TX" onmouseout=
<a href="ProgramInformation.aspx?ID=OK" onmouseout=
<a href="ProgramInformation.aspx?ID=NY" onmouseout=
<a href="ProgramInformation.aspx?ID=CA" onmouseout=
Here is what I came up with:
<a\shref=["](ProgramInformation[.]aspx[?]ID=)(\w{2})["]\sonmouseout=
This worked in Expresso, but did not work in the VS IDE. This also worked in a sample utility I created to test the expression.
Another answerer came up with this:
{\<a:Zshref=["]}{ProgramInformation[.]aspx[?]ID=}{:Al^2}{["]:Zsonmouseout=}
This worked in the VS IDE but not in Expresso. Upon searching I found this link
Ok, here is my question:
Is this a customized RegEx for Windows only?
{} -> Tagged Expression - I thought that this is what this does -> ( ) Grouping.
:Zs -> Space separator -> \s
:Al -> Alpha -> \w
Anybody have some light on this for me?
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com- Edited byJohnGrove Tuesday, May 12, 2009 9:59 PM
Answers
- VS IDE does have a unique regex syntax. I can give some of that history.I was involved on the VS side, so if you need someone to "own up" that would be me and my peers on the editor team at the time.
It was implemented around the same time as .NET was being being developed, but by widely separated teams.
The VS syntax was borrowed and extended (to support Unicode and matching across lines) from the one used by previous Microsoft dev tools. Anyone remember the M editor and PWB?. We looked at other sources of regex syntax and found a number of different camps each claiming to have the One True Syntax. There was AWK, Perl5 was just out, variants of grep, egrep, <name your favorite editor>, and there was this newfangled ECMA stuff starting up (I later found out). We decided to go with what our current customers should have been familiar with, and where we had an existing codebase to work from, free of possible legal entanglements.
In retrospect, I would make a different choice.
Knowing that this would not please everyone, when I designed the Find interfaces, I made it so that it would be easy to plug in other text matching engines (e.g. .NET). AFAIK nobody has taken up that work. I ran out of time the time to expose a formal IDL interface and it was not considered a priority. The underlying machinery is still there, the last I looked. It would be cool if someone on the VS team wired it up and ran some Find in Files races on the two matchers :-).
Note that VS replacement has syntax for left/right justifying the tagged results in space-padded fields. You have to dive deeper into the docs to find it.- Marked As Answer byJohnGrove Tuesday, May 26, 2009 4:20 PM
The IDE Regex is very different, but the concepts are similar enough that a Regex'er should be able to adapt. If you're coding and decide you want to try out the IDE Regex, you can get to the help/cheat sheet pretty quickly by...
1. Shift-Ctrl-H - this brings up the "Find and Replace" dialog.
2. Click on the '+' next to "Find Options"
3. Check the "Use:" check box and make sure "Regular expressions" is selected.
4. Back at the top, under "Find what:", to the right of the ComboBox, there is a button with a right arrow. Click it.
That's your basic cheat sheet.
5. At the bottom of the list, click "Complete Character List".
I've not compared it to the link that John posted above, but it's very close if not identical.
For Replace, go to the next ComboBox down. Click on that Right Arrow button, and you will find help to insert replacement escapes. They are labelled "Tag Expression 1-9". The documentation afore mentioned does not really mention how to form a replacement string. To do that...
1. In your find string, use { } to delimit a tag.
2. You can have many tags.
3. You count your tags from left to right.
4. In your replacement string, you reference your tags with \n where n is a number for the desired tag.
Les Potter, Xalnix Corporation, Yet Another C# Blog- Marked As Answer byJohnGrove Tuesday, May 12, 2009 10:24 PM
All Replies
- Hey John...Visual Studio's expressions are a bastardized version of Regex that no one will own up to, nor does it seem to be related to .Net's regex parser....so no real answer is available.
William Wegerson (www.OmegaCoder.Com)- Marked As Answer byJohnGrove Tuesday, May 12, 2009 10:12 PM
- Unmarked As Answer byOmegaManMVP, ModeratorTuesday, May 26, 2009 3:06 PM
- From xalnix in the other post: [Thank you also xalnix]
Yes. It is a Microsoft IDE specific version of Regex. It's even different from the Microsoft version of Regex for Javascript. That makes 3 versions out there.
They call it a superset, but that's incorrect. A superset would have all the features of the "sub"-set, which it doesn't. It has many new/different meanings for characters we already use. All in all, its just another dialect that you may or may not need to learn. I use the IDE regex sometimes, but not often. But it can be a handy refactoring tool, so its probably worth learning.
By the way, the Find&Replace feature (with Regular Expression checked) has some nice help info to guide you to putting together an IdeRegex that works. The replacement help is absolutely required for those unfamiliar with this flavor.
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com The IDE Regex is very different, but the concepts are similar enough that a Regex'er should be able to adapt. If you're coding and decide you want to try out the IDE Regex, you can get to the help/cheat sheet pretty quickly by...
1. Shift-Ctrl-H - this brings up the "Find and Replace" dialog.
2. Click on the '+' next to "Find Options"
3. Check the "Use:" check box and make sure "Regular expressions" is selected.
4. Back at the top, under "Find what:", to the right of the ComboBox, there is a button with a right arrow. Click it.
That's your basic cheat sheet.
5. At the bottom of the list, click "Complete Character List".
I've not compared it to the link that John posted above, but it's very close if not identical.
For Replace, go to the next ComboBox down. Click on that Right Arrow button, and you will find help to insert replacement escapes. They are labelled "Tag Expression 1-9". The documentation afore mentioned does not really mention how to form a replacement string. To do that...
1. In your find string, use { } to delimit a tag.
2. You can have many tags.
3. You count your tags from left to right.
4. In your replacement string, you reference your tags with \n where n is a number for the desired tag.
Les Potter, Xalnix Corporation, Yet Another C# Blog- Marked As Answer byJohnGrove Tuesday, May 12, 2009 10:24 PM
- Thank you gentlemen
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com - VS IDE does have a unique regex syntax. I can give some of that history.I was involved on the VS side, so if you need someone to "own up" that would be me and my peers on the editor team at the time.
It was implemented around the same time as .NET was being being developed, but by widely separated teams.
The VS syntax was borrowed and extended (to support Unicode and matching across lines) from the one used by previous Microsoft dev tools. Anyone remember the M editor and PWB?. We looked at other sources of regex syntax and found a number of different camps each claiming to have the One True Syntax. There was AWK, Perl5 was just out, variants of grep, egrep, <name your favorite editor>, and there was this newfangled ECMA stuff starting up (I later found out). We decided to go with what our current customers should have been familiar with, and where we had an existing codebase to work from, free of possible legal entanglements.
In retrospect, I would make a different choice.
Knowing that this would not please everyone, when I designed the Find interfaces, I made it so that it would be easy to plug in other text matching engines (e.g. .NET). AFAIK nobody has taken up that work. I ran out of time the time to expose a formal IDL interface and it was not considered a priority. The underlying machinery is still there, the last I looked. It would be cool if someone on the VS team wired it up and ran some Find in Files races on the two matchers :-).
Note that VS replacement has syntax for left/right justifying the tagged results in space-padded fields. You have to dive deeper into the docs to find it.- Marked As Answer byJohnGrove Tuesday, May 26, 2009 4:20 PM
- This should be pinned in this room as it is good info in general from all of you.
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com Paul,
Thanks for owning up. Could you shed some more light on this "easy to plug in another text matching engine" thing. Is this something that has to come from MS, or is the IDE there for anyone to give it a go?
As I said earlier, I don't use the IDE version of Regex that much. The main reason is because I was bringing my understanting of .NET Regex to the IDE and in most cases, it didn't work. It was too different that I felt it wasn't worth learning. However, if it were more like the .NET version, I would be using it a lot more.
Les Potter, Xalnix Corporation, Yet Another C# BlogVS IDE does have a unique regex syntax. I can give some of that history.I was involved on the VS side, so if you need someone to "own up" that would be me and my peers on the editor team at the time.
Paul, let me apologize for my statements. Your hard work had intention, to that I overlooked. My Bad.
Thank you, very much, for bringing this to our attention. Please let us know if there is a way we, the community, can extend any of the VS Regex functionalities.
William Wegerson (www.OmegaCoder.Com)All of us being students of RegEx are aware that there are different "flavors" of RegEx. I started this thread because I didn't realize that .NET had a version that was distinct from Visual Studio. It would make sense to me that both be the same.
I say that with all respect of course not to impugn the hard work involved in making this available to us. Just seems like as I am learning RegEx, every tool I use has their own distinct version. To facilitate this in the .NET world would be to synchronize the VS with .NET if it is at all possible.
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com- I became motivated and posted this suggestion on Microsoft Connect:
Modify Visual Studio Find And Replace To Accept other Non MS Text Matching Engines
William Wegerson (www.OmegaCoder.Com) - John,
There is a third version of Regex that .NET'ers need to consider. That is the MS JavaScript version. It is supposed to be a subset of the .NET Regex, but I haven't proven that to myself. It mainly comes into play when using the RegularExpressionValidator Control in ASP.NET. That control uses a Regular Expression to validate another control's input. The regular expression can be made to run on either the server or the client. If run on the client, it must conform to the more restricted JavaScript Regex, else it throws an exception.
So, Paul, you are not alone at MS when it comes to propagating more and more versions of Regex.
Les Potter, Xalnix Corporation, Yet Another C# Blog - Excellent discussion and thank you William for the submittal as I know it speaks for most of the .NET RegEx'ers.
Also thank you Less for showing us more lack of consistency and the need for fidelity to a spec.
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com - xalnix, VS does not expose a mechanism for extending the search matchers. When I implemented it, I designed it with the capability in mind, and there is an internal Native C++ class level mechanism. We ran out of time to formalize and test the COM interface. Given that there were no clients planning to us it, the feature was cut to focus on other work. Some plumbing is lurking underneath, but would require work from Microsoft to expose (dev, test, document).
Adding .NET matching syntax to the IDE is a perennial request that has always ended up on the chopping block (including VS 2010). If I had stayed on the team I would have pushed for it, but I retired from MS before the product shipped.


