Reputation: 9055
How to use variables inside regexp(to check the existence of a substring ) taking in consideration the following example
var hash = '!price=475;1500&ram=475;1275';
var uri_params = ['price', 'display', 'ram', 'hdd', 'brand'];
$.each(uri_params,function(index, param){
console.log(param);
if(/( !param(.*)|¶m(.*))/i.test(hash)){
console.log('test');
//than here I should add the new value to matched param
}
});
JSFiddle http://jsfiddle.net/lgtsfiddler/c936b/8/
Upvotes: 2
Views: 42
Reputation: 1939
The following will work for parameters in RegExp.
if(hash.match(new RegExp('!' + param + '(.*)|&' + param + '(.*)'))
Upvotes: 1