Need help with regular expression

I

intrader

I can't figure out why VS2005 has a problem with the following definition

Regex rx = new Regex(@"('|\")"); //here put squiggle under ");

what I think I am writing is a regular expresion that will give me all
the matches for single or double quotes and remember the match so that I
can then say

Regex.Replace(somestring,rx,@"\\$1");

Help is greatly appreciated

Thanks
 
D

Dave Sexton

Hi,

In your string you are escaping a " with the escape character, \, however,
you told the compiler that the string is a literal by using the @ character,
so it won't process the \. It sees a string with three quotes so it's
complaining.

When using the @ character to make a string literal, you can escape a
quotation mark with another quotation mark:

@"('|"")"
 
I

intrader

Dave said:
Hi,

In your string you are escaping a " with the escape character, \, however,
you told the compiler that the string is a literal by using the @ character,
so it won't process the \. It sees a string with three quotes so it's
complaining.

When using the @ character to make a string literal, you can escape a
quotation mark with another quotation mark:

@"('|"")"
Fantastic, Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top