The Visual Studio IDE and Regular Expressions

So, this will be in Orcas, right? Right?? :wink:

But in all seriousness, thanks for letting us know you’re out there and thinking about this stuff. It is appreciated.

Daniel Read - I’ve never had a problem with that. Try Alt+Ctrl+V

The implementation is buggy anyway. Who would use an unreliable regexp-replace feature, that requires manual inspection of the result afterwards?

I have many times attempted to do a regexp-replace that did not match correctly: An example is copying an array from Excel, resulting in tab-seperated text in VS, using this (in hope the HTML-ifier engine wont ruine it) regexp to convert into C# did not work:
Find: "^{:n}\t{:n}$"
Replace: “{ \1 , \2 },”

The result was many empty lines like “{ , },”, further if I removed match start and end, using “{:n}\t{:n}”. Then not all digits at the end of the line was matched (betst result was achieved when cliking individual “Replace” oposed to “Replace All”.

Going back to XEmacs.

Jarl

Saw a cool replacement that does what you suggest.

http://channel9.msdn.com/ShowPost.aspx?PostID=181063

You can even wire it up to CTRL+H manually for the Text Edit, so it appears instead of the usual Find/Replace dialog.

I wish Visual Studio (and specifically the C# and VB.NET code
editors, which I understand are not really part of Visual Studio
proper, but rather more like plugins) were more like a good text
editor; instead, I find it sometimes gets in my way because it’s
trying to be a code editor when I just want it to be a text editor.
It would be cool if there was a way to switch out of “smart code
editor” mode into “get out of my way and just be a text editor” mode.

My thoughts exactly. I wish their intentions were to build a professional programming editor first and integrate their product specific stuff second. This is why I always have to have an alternate editor on standby and I wish that weren’t necessary.

For the problem that “finds each subsequent letter in the word”, you can resolve it by enabling “Match whole word” in the find/replace dialog.
Once again, M$ sux!

There’s a better regex search replacement tool for VS2005 available at:

http://channel9.msdn.com/ShowPost.aspx?PostID=181063

I believe the FR dialog should have “Regular Expression” and “Regular Regular Expression”

Someone please explain this Visual Studio Find and Replace (FR) behavior when using prevent match
in a regular expression. It appears to be a bug, but maybe I am missing something. It is easy to
reproduce. I am using Visual Studio 2005 (it happens with and without Service Pack 1).

When using the following find against the XML line shown, it correctly finds the
first occurrence of “copyright”. Find again skips the second “copyright” as expected:

report-option name=“copyright-notice” value="{//field[@name = ‘item-copyright’]/@value}"/

Now try the same find, only this time put parenthesis (or squirly brackets) around the expression:

This time when find again is used the second “copyright” is incorrectly matched.

I have found other bugs too. One particularly destructive that happens with replace in files,
producing unexpected results in different files every time it is used. Run it one time and it
works correctly for file 1 and incorrectly for file 2. Restore the files and run it again.
This time it might work incorrectly for file 1 and incorrectly for file 2. A third time, it might
work incorrectly for file 1 and correctly for file 2. It is completely unpredictable every
time it is used against the same files. Now imagine it with 1000 files. It is very ugly.

With such bugs, it is really hard for me to depend on FR.

Does anyone know of a good site documenting the known bugs, peculiar behavior, and types of finds
(and replaces) that should be avoided when using Visual Studio FR?

P.S. I too would like to see FR use the same expression syntax as the framework.

The following line is the XML for my previous post without the opening and closing and . This sight removed that line from my previous post.

report-option name=“copyright-notice” value="{//field[@name = ‘item-copyright’]/@value}"/

The second find should have been {~(-)copyright} rather than {[]~(-)copyright}. Note that there is a tilde preceding (-) in both cases, which this site is also removing.

I’ve posted a complete phrasebook between the VS editor regex syntax and normal regex syntax: http://brianary.blogspot.com/2008/05/visual-studios-nih-regex-syntax.html

There is a new tool Regent (http://www.regexinference.com) that tries to infer search and replace regular expression from text example. It supports both Visual Studio regex syntax and ECMAScript/Perl syntax. Not a freeware though.

Sometimes a slash appears on the Visual Studio IDE while working with code-behind file. It does not effect any functionality. Can anyone explain why this happens?
Mail to sanjayvigil@yahoo.co.in

Yeah, your article does say it clearly, but as Im new to both regex expressions and VS IDE’s regular expressions, I really dont have a problem with which I use to get my work done… Both are new to me anyway

I have provided a link to this page from my blog, hope you dont mind. http://pcriddler.blogspot.com/2008/11/using-vs2005-ide-regular-expressions.html

Is there any hope?

I’ve been lamenting the Visual Studio regex syntax for years, and I’ve seen no sign that it will ever support even the .net regular expression syntax.

Great post! If you’re looking for a free plugin that provides actual, standard-syntax regex support, I’ve found this one to work pretty well:
http://www.codeproject.com/KB/macros/VS2005RegexAddIn.aspx?fid=1405582df=90mpp=25noise=3sort=Positionview=Quickselect=2950706fr=1

What will be the regular expression for RAISEROR function of Sql server ?

I can’t believe they’re still doing this. At the least they could provide an option that uses the System.Text.RegularExpressions library.

The idiocy of their proprietary regexs has been carried over into Sql Management Studio as well. Why? It’s not like they have backwards compatibility issues there.