1

Is there any helper function in (ASP).NET library that properly escapes .NET regex patterns to be used in javascript? So that i don't need manually escape + quantifiers, etc. As far as i understand RegularExpressionAttribute from Data Annotations performs proper translation. Can i reuse it somehow?

1
  • 1
    I've not used it but msdn.microsoft.com/en-us/library/… may help. Looks like it should take any string from .NET and make it into a valid string in javascript (by escaping stuff, etc.). Commented Feb 6, 2012 at 15:14

1 Answer 1

2

Escape() is your friend:

string escapedInput = Regex.Escape(input);

Turns, for instance, "a+b" into "a\+b".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.