Replace #include <*> with #include “*” using regular expression in Visual Studio

If for some reasons you wan’t to replace all your #include <*> with the equivalent form #include “*” you can use the Find and Replace regular expression in Visual Studio to do it.

Find what:

\<gtl{.*[/\\].*}\>

Replace with:

"gtl\1"

Quick explanation: {.*[/\\].*} is a match that will be kept using \1.

This will replace this:

#include <gtlGraph/AbstractNode.h>
#include <gtlUtil/Observer.h>

into this:

#include "gtlGraph/AbstractNode.h"
#include "gtlUtil/Observer.h"

Here I’ve used gtl as a base search, but you could replace it with anything you need. I didn’t want to replace all system includes, but only my library includes, so that’s why I’ve specified the gtl as a prefix.

This entry was posted in Coding and tagged , , , . Bookmark the permalink.

One Response to Replace #include <*> with #include “*” using regular expression in Visual Studio

  1. Robert says:

    Here’s how you can replace backward slash with forward slash using a regular expression:

    Find: \#include {.*}\\{.*}
    Replace with: \#include \1/\2

Leave a Reply

Your email address will not be published. Required fields are marked *