views:

129

answers:

3

hi all,

i'm trying to create a regex pattern out of a variable like:

var tag = "style";
var pattern = "/<"+tag+"[^>]*>((\\n|.)*)<\\/"+tag+">/gi";

but it won't work - anyone can tell me what's wrong?

thx

+1  A: 

In general, matching html tags with regex isn't a good idea. See explanation here.

James Kolpack
+1  A: 

Use the RegExp object

var tag = "style";
var pattern = new RegExp("<"+tag+"[^>]*>((\\n|.)*)<\\/"+tag+">","gi");
PetersenDidIt
A: 

var re = new RegExp(string) ..

see here

Scott Evernden