3

The following regular expression is workable using C# reg ex:

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

It matches string such as:

#http://localhost/tableaux-p145717.htm=&_surveyForm=second

or

#_surveyForm=second

I used named capturing groups.

I know Javascript doesn't take advantage of named capturing groups (instead it uses \1, \2, etc.). Besides the syntax is slightly different from the one above.

How can I make that reg ex javascript-compliant?

Thanks in advance,

R.

2 Answers 2

4

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.

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

Comments

0

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+)$/

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.