#### Archived

This topic is now archived and is closed to further replies.

# Regular Expressions in Visual Studio

This topic is 5778 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi! I just found out you can write regular expressions inside Visual Studio "Find/Replace" dialog boxes. Wow, this is really useful.. However, when I try to include the newline \n, inside the expression, it just acts as if I typed the letter n! Does anyone know how to include the newline character? Thanks a lot! Raj

Maybe $or ^ will work (I can''t remember which matches end of line)? #### Share this post ##### Link to post ##### Share on other sites Yeah, they''re done on a line-by-line basis (like grep) so you need to use the$ character.

If I had my way, I''d have all of you shot!

codeka.com - Just click it.

##### Share on other sites
Hmm thanks a lot! That seems to work for finding the end of the line. When I try to actually insert an end-of-line though, using the Replace dialog box, it just inserts a dollar sign. Any idea of how to get around that?

Thanks a lot!

Edit: By the way, it might help to show what I'm trying to do. Basically, I'm trying to generate empty functions from the prototoypes, because this saves a lot of redundant manual editing. So, say I had this bunch of functions taken from a "Graphics" class:

Graphics();
void SetMode(int modeNumber);
void VSync();

Then, I could use regular expressions to convert this into:

Graphics::Graphics()
{
}

void Graphics::SetMode(int modeNumber)
{
}

void Graphics::VSync()
{
}

But, since I can't get newlines to work on the "Replace" dialog box, all I end up with is stuff like this:

Graphics::Graphics() {}
void Graphics::SetMode(int modeNumber) {}
void Graphics::VSync() {}

Thanks =)

Raj

[edited by - Rajansky on January 21, 2003 9:35:11 AM]

##### Share on other sites
You''re going to have to go back and edit it anyway so you could leave it as it is. You''ll need to make sure you return the correct type for non-void returns. Not hard, but a bit precarious if you ask me, you''ll have code which compiles nicely enough but does nothing.

If it''s backed up with tests and you''re following the practice of writing code which deliberately fails first time through, just to get the tests in place, then you''ll have a better chance of catching the bugs.

##### Share on other sites
I guess you could cut and paste a new line from the text editor into the replace box. I do that a bit with tabs (which you can''t type into there either).

If I had my way, I''d have all of you shot!

codeka.com - Just click it.

##### Share on other sites
you guess wrongly

##### Share on other sites
Actually, you can do tabs, with \t

Ahh oh well I give up, I don''t think it can be done in VS 6. I guess, maybe there''s some better way to do it using Visual Studio macros.

Raj

use perl or ruby

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011472
• ### Who's Online (See full list)

There are no registered users currently online

×