Forum Moderators: open

Message Too Old, No Replies

variables and regular expression

         

andrethegiant

11:31 pm on Jul 23, 2005 (gmt 0)

10+ Year Member



is it possible to insert a variable into a regular expression string? for example, something like this:

reg = /name="val"+i+"" value="[\w]+/gi

where i is the variable (an interger, let's say). then this should work for val0, val1, val2, etc.

Well, at least that's what I want. Please help!

Dijkgraaf

4:58 am on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, find a similar example below

re = "/^\\d{0," + (sLength) + "}$¦^\\d{0," + (sLength) + "}\\.\\d{0,2}$/";
re = eval(re);

You first need to create the string you want, and then use the eval function.

Later on you then use
re.test(sObjectValue)