Today I Learned

Remove/change modifiers of an existing regexp

The following regexp has a couple of modifier:

const regexp = /my-project-id/gi
// -> /my-project-id/gi

to reuse the existing regexp and remove the modifier, create a new instance of the regexp with a blank modifier:

const regexp2 = new RegExp(regexp, '')
// -> /my-project-id/

You can also omit modifiers from existing ones specified in the regexp:

const regexp3 = new RegExp(regexp, regexp.flags.replace('g', ''))
// -> /my-project-id/i