0

I am trying to use the following regex in c#

<asp:(\w+)\s+.*?id="(\w+)"

I cannot seem to store it as a string without corrupting it.

How can I escape the expression and maintain its integrity?

Thanks

spanout
  • 165
  • 1
  • 2
  • 10
  • 1
    related: http://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions or even better: http://stackoverflow.com/questions/4275904/c-sharp-regex-escape-sequences – Vogel612 Sep 09 '13 at 13:46

2 Answers2

5
string pattern = @"<asp:(\w+)\s+.*?id=""(\w+)""";
I4V
  • 34,891
  • 6
  • 67
  • 79
-1

Use this Regex.Escape() method.

Regex.Escape("<asp:(\w+)\s+.*?id=""(\w+)""");
Bibhu
  • 4,053
  • 4
  • 33
  • 63