Create RegExps on the fly using string variables

There’s new RegExp(string, flags) where flags are g or i. So

'GODzilla'.replace( new RegExp('god', 'i'), '' )

evaluates to

zilla

Leave a Comment