gpt4 book ai didi

javascript - 正则表达式在Javascript中获取具有复杂结构的字符串

转载 作者:行者123 更新时间:2023-12-04 16:08:48 24 4
gpt4 key购买 nike

我有一个链接看起来像:

var str = "http://example.com/ep-1-29838.html";

我只想得到29838

我试过:

str = str.replace(^([-])\/([.html])$\w+, "");

我没有太多使用 Regex 的经验。谢谢。

最佳答案

匹配最后的数字后跟一个点和文件扩展名:

var str = "http://example.com/ep-1-29838.html";
console.log(
str.match(/\d+(?=\.\w+$)/)
);

关于javascript - 正则表达式在Javascript中获取具有复杂结构的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50793506/

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