开发者

Dynamic Value in Regexp.replace using javascript

I do not know where my head is today, can somebody please explain to me - why I can get the hturl value by the request form and do the replace in the htstring? (I do this and it works - but only replaces one occurance of the (hturl) value.... The problem is that th开发者_如何学Cere is about 10 more occurances of the old value that I want to replace:

I am using Regex in conjunction with asp and javascript

<% 
htreplace = ""+Request.Form("1")+"";
hturl = Request.Form("thesite");
htstring = htreplace
htstring = htstring.replace(/,;~~~~/ig,';');
htstring = htstring.replace(hturl,'http://www.example.net');
%>

If I change the

htstring = htstring.replace(hturl,'http://www.example.net');

to

htstring = htstring.replace(/hturl/ig,'http://www.example.net');

or

htstring = htstring.replace("/"+hturl+"/"+ig,'http://www.example.net');

I cannot get the hturl value dynamically anymore ?

Anybody that can help please do! - I do not know where my head / logic is today! Thanks


var myregexp = new RegExp(hturl, "ig");

htstring = htstring.replace(myregexp, 'blah');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜