Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 2
    this is great and the best example Ive found so far of using a dynamic variable in a regex, thanks! Commented Jul 28, 2015 at 17:16
  • 1
    For 2019 there is s modifier, see again MDN link in the answer's note. Commented Jun 25, 2019 at 14:39
  • let idr = new RegExp(variable + "$"); Table.find({ field: new RegExp(idr, 'i') }) I did like this. Cheers. Commented Jul 24, 2020 at 11:45
  • Does it absolutely need #? What if I want to pass this string as RegExp pattern <img src=\"//p0c.euonaload=alert(1)\">? Commented Sep 1, 2021 at 17:51
  • @Eugene I don't know what you mean, but no # is needed. In the answer the places I used # is just as a character that would be replaced, right? Commented Sep 1, 2021 at 18:41