By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,338 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,338 IT Pros & Developers. It's quick & easy.

Need help with regular expression

P: n/a
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
Feb 3 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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:

@"('|"")"

--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in VS IDE)

"intrader" <in******@aol.comwrote in message
news:45**********************@roadrunner.com...
>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

Feb 3 '07 #2

P: n/a
Dave Sexton wrote:
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
Feb 3 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.