我有一个链接看起来像:
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/