Is there a good way to turn regex patterns into properly-escaped c# regex patterns?

  • Thread starter sherifffruitfly
  • Start date
S

sherifffruitfly

.... Becuase GOD am I getting sick of happily whipping out a rexex
pattern, and then spending 45 minutes squinting my eyes at the c#
code, trying to see if I have 4 backslashes, or only 3.


Suggestions greatly appreciated,

cdj
 
S

sherifffruitfly

Use the '@' operator:

string escaped = @"abc\d/efg";


It doesn't, because my patterns oftentimes have quotation marks in
them, which require escaping.
 
J

Jon Skeet [C# MVP]

sherifffruitfly said:
... Becuase GOD am I getting sick of happily whipping out a rexex
pattern, and then spending 45 minutes squinting my eyes at the c#
code, trying to see if I have 4 backslashes, or only 3.


Suggestions greatly appreciated,

I suspect it wouldn't take very long at all to write a little
application (web or winforms) which let you type in either the C#
version and see what it really is, or the "real" version and see what
that should be in C#.

If you have many regular expressions in an application, you could keep
them in a resource file of some description, and refer to them by name.
That way you could do without any extra escaping.
 

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