I have a hash of "allowed links" to render on my rails backend, something like this
ALLOWED_URLS = {
"vimeo": {
:regex => "/https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/",
},
"youtube": {
:regex => "/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/",
}
In each of the stored values, I have a regular expression to try if a link is from youtube or Vimeo and the video id I have tried them both and they work perfectly.
But when I pass that variable to my CoffeeScript and convert it to a JSON, the regex does not work because it comes with quotation marks, like this:
"/https?://(?:www.|player.)?vimeo.com/(?:channels/(?:w+/)?|groups/([^/]*)/videos/|album/(d+)/video/|video/|)(d+)(?:$|/|?)/"
and when I try to test it, this error is shown...
Uncaught SyntaxError: Invalid regular expression: //https?://(?:www.|player.)?vimeo.com/(?:channels/(?:w+/)?|groups/([^/]*)/videos/|album/(d+)/video/|video/|)(d+)(?:$|/|?)//: Nothing to repeat at String.matc
I've tried to put the regex without the quotation marks on the backend, but the result is the same
What can I do??
regex: /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|.../(i.e. drop the surround quotes).