...

View Full Version : Regexp replace with function



scroots
06-08-2004, 09:37 PM
I am trying to write a regular expression to match a pattern and replace ti witnh the result of a function. I can get the pattern to match its the function part that is gonig wrong.

my code


x=x.replace(/(%[0-9][a-z])/g, unescape($1));

any ideas?

scroots

fredmv
06-08-2004, 10:55 PM
I believe what you want is:
unescape(RegExp.$1)

scroots
06-09-2004, 10:22 AM
thanks i will try that later on when i'm at home.

scroots

liorean
06-09-2004, 01:09 PM
var x='string%20here';
x=x.replace(/(%[0-9a-f]{2})/g, function(m,p){
return unescape(p);
}));

scroots
06-10-2004, 09:08 PM
thanks everyone your solutions work, it cleaned up how to pass a regualr epxression value to a function.

thanks again

scroots



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum