Qingwei
Qingwei

Reputation: 510

JavaScript RegExp with multiple modifiers

Is it possible to have regex with both g and s modifier?

I've tried

/abc/gs                         // throw error
new RegExp('abc', 'g', 's')     // s is ignored
new RegExp('abc', 'gs')         // throw error
new RegExp('abc', ['g', 's'])   // throw error

Upvotes: 0

Views: 3120

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115222

You can get the answer from the error thrown

Uncaught SyntaxError: Invalid flags supplied to RegExp constructor 'gs'(…)

There is no s modifier in JavaScript regex. So it's an invalid regex that's why it's throwing error. The available modifiers can be check on documentation.

Upvotes: 4

Related Questions