The Visual Studio IDE and Regular Expressions

Once again

Standards? For RegEx? You standards-whiners crack me up. Why doesn’t your Web site follow the standards for good navigation layout? Why don’t you follow the standards for whining all the time? Because there are no standards for those things, just like there are none for RegEx. You need to come to grips with the fact that the freedom to create and express results in differences. Overall, that is great. Accept that and you’ll free up a ton of whining time that you can use to do something productive.

@Jeff,
‘There’s no “standard” C++’

Huh?
So what is ISO/IEC_14882?

Of course the existence of a standard doesn’t mean that everyone adheres to it. But still, there is a standard.

Lars

Stop writing about things that you clearly have no clue about. How is (("[^"]")|(’[^’]’)) supposed to match a quoted string, especially one that contains “? Or a @-verbatim string that contains “”? And how quickly can you type ((”[^"]")|(’[^’]’)) compared to :q?

And why do you keep reiterating that there is no equivalent to in standard regexes when clearly there is \b? Read up on some basics before making stupid claims that are obviously false.

I have often considered using VI or EMACS as an editor for C++ code, in conjunction with the Visual Studio compiler, linker, etc.

The Visual Studio “text editor” really makes my blood boil at times, e.g. when I accidentally hit F1, or when it re-formats some of my code in an effort to “help,” or when its schizophrenic threading model wanders off into the sunset with the CPU, leaving me alone with my thoughts.

But I fear one big problem: that any concept of a “solution” or “project” will likely be lost when working in another editor. I work on projects with huge numbers of files spread all over the place, so it’s nice to be able to use the “Entire Solution” option of “Find In Files” to really search globally. It’s also nice to be able to easily access (via the Solution Explorer) all the project files.

All of this comes with the caveat that #include trumps the Visual Studio concept of “project files” when it comes to determining exactly what constitutes your project. So the Visual Studio features I mention are really not well-implemented any way, and if EMACS or VIM can offer a plausible alternative, I want to explore that.

Do VIM and EMACS allow anything like project- or solution-level searching? Perhaps something can be simulated using the file system. Otherwise, these programs are probably excellent for single-file projects (or those with only a few files).

Incidentally, it seems to me that most Visual Studio projects contain an inordinant, even ridiculous number of files. I documented this in a thread on DailyWTF.com once and got flamed mercilessly for it. Apparently, the collective opinion is that requiring 14 files with 6 different extensions just to print “Hello, World” is de rigeur in Today’s Modern World, and I should just get with the program, deal with it, and Install Silverlight Or Else.

Nevertheless, I wonder if this “file logorrhea” exhibited by Visual Studio reflects an effort (at whatever level of consciousness) to make this product less amenable to the use of non-Microsoft text editors.

It’s the grouping operator (ok, ‘tag expression’) that always catches me - I try every combination of () and () and it doesn’t work - ah, that’ll be because MS decided to use braces. Bah.

As to the behaviour you saw with searching for “[A-Za-z]+” - it strikes me that VS restarts the search one character after the start of the last match, rather than straight after the end of the last match.

Not sure I’d agree with “…searching with regular expressions is such an extreme edge condition…” either, but then maybe I’m just regex-happy :slight_smile: Certainly happy with regexes, anyway!!

You can do some cool stuff with regex capture groups in VS.NET Find / Replace, too:
http://weblogs.asp.net/jgalloway/archive/2003/05/24/7498.aspx

Jeff, thanks for this post. Saved my butt.

Hi Jeff,

I know this is off the wall, but the correct way to perform your first example would be: “<[A-Z]+>” (minus the quotes), instead of “[A-Za-z]+”. The ‘<’ and ‘>’ characters match the whole word only instead of the word and the individual characters in it. Certainly, less than obvious : )

What I’m trying to figure out is how to use a regex in the “Replace with” instead of a literal. I don’t even know if this can be done…

Dave Black

I should have added in my previous post that I’m trying to turn all uppercase params/variables into lowercase with a preceeding underscore…

Thanks for a very useful post. I was hoping to searh for particular search terms which had NOT been commented out.

To exclude comments from your rexed search, use

^~(:b*’)

which effectively means at the beginning of the line exclude any amount of white space (to allow for auto-indented comments) followed by the apostrophe comment character.

To find conditional stops that have not been commented out use

^~(:b*’).*:b+Stop(:b+|\n)

Curiously, VIM uses ‘<’ for beginning of word, ‘>’ for end of word, in its enormous language-parser regex syntax. So now there are at two instances of using the same (well, very close) symbols for the start/end word match.
(http://vimdoc.sourceforge.net/htmldoc/pattern.html#pattern)