【发布时间】:2023-03-24 18:33:02
【问题描述】:
这个脚本应该获取一个链接列表,通过更改一些单词来转换一些链接,并删除包含特定字符串的其他链接。
第一部分还可以。我需要第二个帮助。线
x = x.replace(/^.+/category/.+$/mg, "");
即使我们将 + 更改为 * 也不起作用。我使用了这里的资源(1 & 2)。所以,帮助菜鸟。
<!DOCTYPE html>
<html>
<body>
<h3>Instert your links</h3>
input:<br>
<textarea id="myTextarea">
http://example.com/ad/123.html
http://example.com/ad/345.html
http://example.com/ad/3567.html
http://example.com/category/fashion.html
http://example.com/ad/8910.html
http://example.com/category/sports.html
</textarea>
<button type="button" onclick="myFunction()">Get clean links</button>
<p id="links"></p>
<script>
function myFunction() {
x = document.getElementById("myTextarea").value;
x = x.replace(/http:\/\/example.com\/ad\//g, "http://example./com/story/");
x = x.replace(/\n/g,"</br>");
x = x.replace(/^.+/category/.+$/mg, "");
document.getElementById("links").innerHTML = x;
}
</script>
</body>
</html>
【问题讨论】:
-
所以你想删除其中包含
category的行?
标签: javascript