使用 javascript 的 Regexp.replace 中的动态值

发布于 2024-08-13 22:11:18 字数 773 浏览 2 评论 0原文

我不知道我今天的头在哪里,有人可以向我解释一下 - 为什么我可以通过请求表单获取 hturl 值并在 htstring 中进行替换? (我这样做并且它有效 - 但只替换了一次出现的 (hturl) 值...问题是我想要替换大约 10 次旧值:

我正在将 Regex 与asp 和 javascript

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

如果我更改

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

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

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

我无法再动态获取 hturl 值?

有人可以帮忙吗?我今天不知道我的头/逻辑在哪里,谢谢!

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 there 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗化ㄋ丶相逢 2024-08-20 22:11:18
var myregexp = new RegExp(hturl, "ig");

htstring = htstring.replace(myregexp, 'blah');
var myregexp = new RegExp(hturl, "ig");

htstring = htstring.replace(myregexp, 'blah');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文