I need a function to get only empty href request parameter names, so I can replace them later with values from another array. After several hours of failure with regular expressions, I turned to:
function getEmptyQueryParams(URL)
{
var params = new Array( );
var non_empty_params = new Array( );
var regex = /[\?&]([^=]+)=/g;
var regex2 = /[\?&]([a-zA-Z_]+)=[\w]/g;
while( ( results = regex.exec( URL ) ) != null )
{
params.push( results[1] );
}
while( ( results = regex2.exec( URL ) ) != null )
{
non_empty_params.push( results[1] );
}
while(non_empty_params.length > 0)
{
for(y=0;y < params.length;y++)
{
if(params[y] == non_empty_params[0])
{
params.splice(y,1);
}
}
non_empty_params.shift();
}
return params;
}
It works, but it looks ugly, like hell ... Is there a better way to do this? Any help is appreciated.
source
share