Alex Rivera | Logout

How can I concatenate regex literals in JavaScript?

Asked 2008-10-09T00:43:12.760
199

Is it possible to do something like this?

var pattern = /some regex segment/ + /* comment here */
    /another segment/;

Or do I have to use new RegExp() syntax and concatenate a string? I'd prefer to use the literal as the code is both more self-evident and concise.

Edit
Report

1 Answer

-3

I prefer to use eval('your expression') because it does not add the /on each end/ that ='new RegExp' does.

answered 2009-04-15T15:12:18.587

Your Answer