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

标签 javascript regex

我有一个链接看起来像:

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/

相关文章:

javascript - 将 Javascript 正则表达式转换为 PHP 正则表达式?

javascript - 在左上角制作一个重新加载按钮

javascript - 在 JavaScript 中是否可以定义负数的平方根?

javascript - 什么是 SignalR Hub?如何重命名?

javascript - 使用 jQuery 解析 JSON 数据

r - 在 R 中用 n 个单词拆分字符串

regex - 谷歌电子表格: Conditional formating based on text in another sheet

javascript - 如何用变量值替换所有带有特定前缀的字符串

python - 为什么下划线不能匹配 '\W' ?

java - S1 包含带有正则表达式的 s2