My regex breaks when I "alert" it - because of escaped slashes?
I'm currently working on a CKEditor plugin which would add internal links to our CMS. One of the thing their current link plugin does is that it'll parse through a link when开发者_开发问答 it loads the link dialog to figure out what "type" it is.
Since I created the internal type I need to add a regular expression to compare it to and I'm having trouble doing so. I managed to match my expression using this tool but once I use the same expression in the RegExp object definition it doesn't seem to work.
My links look like this:
/en/my_folder_5
or
/fr/my_folder_5
I tried the following (which worked in that tool):
/(en|fr)/[A-Za-z_^/]+_[0-9]+
but all the slashes get escaped when I "alert" the expression (which leads me to believe it might be what's breaking it since I copy pasted the alerted expression and it did not work)
Any help is appreciated :)
var regex = /\/(en|fr)\/[A-Za-z_^\/]+_[0-9]+/;
alert(regex.test('/fr/my_folder_5')); // prints true
精彩评论