2

I'm using this url regex from the RFC-3986

And it is written here :

^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?

It is working for me here

But when I add it under visual studio , I see this : enter image description here

And chrome developer toolbar shows me this :

enter image description here

What am I doing wrong ?

p.s. I thought that there are maybe hidden chars - so I pasted in CMD and then re-copied it , but still....

Royi Namir
  • 144,742
  • 138
  • 468
  • 792

1 Answers1

2

Escape all occurrences of / as \/. Then, VS will not complain.

var basicRegexPatterns = {
    urlPattern: /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/i
};

See Escaping a forward slash in a regular expression.

Community
  • 1
  • 1
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • thos escaping problems gonna kill me..... where can i find all(!) the chars which should be escaped (js)? this answer doesnt indicate `/` http://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions – Royi Namir Jul 31 '13 at 07:45
  • @RoyiNamir, That answer is dealing with the regular expression itself. `/` in your question is regular expression literal delimiter (like `"` / `'` for string literal). – falsetru Jul 31 '13 at 07:49
  • Oh - you are saying that the middle `/` is treated a new regex expression....?however I found that answer http://stackoverflow.com/a/17326679/859154 which shows what mdn sais which is what i asked. thanks. – Royi Namir Jul 31 '13 at 07:50