471,350 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Regex for escaping

My C# code writes out javascript to the page and to do that certain
characters need to be escaped. So if the javascript string shows "Customer:
Bob's Diner" i have to change Bob's to Bob\\'s

i tried writing a regex replace to do this but apparently don't know how.
What i tried was:

string charactersToEscape = @"'\\"; //--- apostrophe and \ for \n
string result = Regex.Replace(text, "[" + charactersToEscape + "]", "\\$1");

The $1 syntax obviously isn't right. i tried a named group like <x> but
apparently don't know the syntax quite right for that either


Jul 29 '05 #1
0 826

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Theo Chakkapark | last post: by
1 post views Thread by GlennH | last post: by
2 posts views Thread by Jeff Jarrell | last post: by
4 posts views Thread by ad | last post: by
15 posts views Thread by morleyc | last post: by
3 posts views Thread by bob | last post: by
3 posts views Thread by chemicalcold0 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.