How to install modifier in coffeescript heregex?

I have this heregex in coffeescript trying to catch the urls:

regex = /// (
  ((f|ht){1}tp(s)?://)
  [-a-zA-Z0-9@:%_\+.~?&//=]+
  )
///

but how to set a global flag and ignore the flag? I tried this:

    newregex = regex.compile(regex,"gi")

but it does not work.

+3
source share
1 answer

Coffeescript converts your heregex into one regex:

//Generated by CoffeeScript 1.3.1
var regex;

regex = /(((f|ht){1}tp(s)?:\/\/)[-a-zA-Z0-9@:%_\+.~?&\/\/=]+)/;

And javascripts regex syntax /regex/modsis shorthand for regex.compile ("regex", "mods"), so you don't need to compile it. You can simply add modifiers to heregex:

regex = /// (
  ((f|ht){1}tp(s)?://)
  [-a-zA-Z0-9@:%_\+.~?&//=]+
  )
///gi
+6
source

All Articles