how to store Multiple pattern parameter in variable and print ihe values of that variable in JavaScript -
i have str variable in string there
var str = "the 1_raj in spain stays mainly3_raj in 1_rajthe plain 2_raj 4_raj 6_raj_1_raj";
var res = str.match(/1_raj/g);
i want store( 1_raj,2_raj,3_raj,4_raj,...etc ) in res variable can diffirent(1_raj,2_raj,3_raj,...) values in variable res
thanks
use regular expression result,
var res = str.match(/[0-9]{1}_raj/g);
to match 0_raj
, 1_raj
, .. 9_raj
change value bracket if value more 9 10_raj
var res = str.match(/[0-9]{2}_raj/g);
now can use separate values looping through array 'res'.
for(var = 0; < res.length; i++) { alert(res[i]); // here each value separately, want. }
hope works. thanks.
Comments
Post a Comment