Visual Studio, Find and replace, regex

RegexVisual Studio-2005Replace

Regex Problem Overview


I am trying to replace all the #include "whatever.h" with #include <whatever.h> using find and replace functionality in Visual Studio 2005. I used the regex \#include \"[a-z\.h]+\" to find the include statement. But I am wondering how frame the replace regex.

\#include \<[a-z\.h]+\> did not work and won't; it replaces the statement #include "whatever.h" with #include <[a-z.h]+>. How shall I frame the replace regex to retain whatever.h as it is?

Regex Solutions


Solution 1 - Regex

For versions before Visual studio 2012:
It works when I do this:
find include "{[a-zA-Z]+\.h}",
replace with include <\1>.
The most relevant parts for your question are the curly braces {} and the back reference \1: \n references to the n'th group indicated by curly braces in the search expression.

For versions Visual studio 2012 & up:
Starting with VS2012 .NET Framework regular expressions are used. So there it should be:
find include "([a-zA-Z]+\.h)",
replace with include <$1>.

Solution 2 - Regex

You need to select both Match Case and Regular Expressions for regex expressions with case. Else [a-z] won't work.enter image description here

Solution 3 - Regex

It's also possible with the short version:

Short version

https://regex101.com/r/vW7Rbh/1

Solution 4 - Regex

here is my use case I need to find all the html comments like this

<!--begin::Info-->
<!--End::Info-->

this is what I used

((<!--.+?-->)|('.+?'))

I hope it can be helpful for someone

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbdharView Question on Stackoverflow
Solution 1 - RegexMielView Answer on Stackoverflow
Solution 2 - RegexDavid MorrowView Answer on Stackoverflow
Solution 3 - RegexAndreas KarzView Answer on Stackoverflow
Solution 4 - RegexdnxitView Answer on Stackoverflow