Skip to content Skip to sidebar Skip to footer

Convert C# Regex To Javascript Regex

The following regular expression is workable using C# reg ex: ^(?#_surveyForm.+)|#(?:(?http.+\.\w{3,4}).+_surveyForm=\w+)$ It matches string such as: #h

Solution 1:

As you said, JavaScript doesn't support named captures. You have to change those into "normal" capturing groups and refer to them by number instead of by name:

/^(#_surveyForm.+)|#(?:(http.+\.\w{3,4}).+_surveyForm=\w+)$/

You should also be aware that \w only matches ASCII alphanumerics in JavaScript whereas it matches Unicode alnums in .NET.

Solution 2:

You could use something like:

/^#(http.+.\w{3,4}.+)?_surveyForm=(\w+)$/

Your URL will be in first capturing group, and the survey in the second.

This expression would probably work better for you:

/^#(https?:\/\/\S*)?\b_surveyForm=(\w+)$/

Post a Comment for "Convert C# Regex To Javascript Regex"