gpt4 book ai didi

Javascript 替换

转载 作者:行者123 更新时间:2023-11-30 07:18:43 26 4
gpt4 key购买 nike

大家好,在这里挣扎......

是否可以将第一个正斜杠之间的任何内容替换为“”,但保留其余部分?

例如var 将是

string "/anything-here-this-needs-to-be-replaced123/but-keep-this";

会变成这样

string "/but-keep-this";

希望有意义

最佳答案

你可以简单地用/分割它

var str = "/anything-here-this-needs-to-be-replaced123/but-keep-this";
var myarray = str.split('/');
alert('/' . myarray[2]);

关于Javascript 替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3028578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com