user642178
user642178

Reputation:

Add variable to RegEx

For example, I've got var for RegEx DSX-?2 I need add this var to RegEx and get this .match(/DSX-?2/gi)

Upvotes: 2

Views: 581

Answers (2)

splash
splash

Reputation: 13327

You can create a RegExp object by using the new RegExp() constructor or by assigning a RegExp literal to a variable:

var pattern1:RegExp = /DSX-?2/gi;
// or
var pattern2:RegExp = new RegExp("DSX-?2", "gi");

Upvotes: 3

user642178
user642178

Reputation:

var reg:RegExp = new RegExp("DSX-?2", "gi");

Upvotes: 0

Related Questions