使用Regex在斜线之间抓取值

Grab Values between Slashes using Regex

本文关键字:之间 抓取 Regex 使用      更新时间:2023-09-26

http://example.com/...../post/index/88/mike-hey-dddd

我需要拿##

索引/###/

"##"表示数值。

我计划运行regex is javascript。

您可以使用'/来转义要在正则表达式中使用的斜杠:

所以结果是:

var input = "http://example.com/...../post/index/88/mike-hey-dddd";
var match = input.match(/'/index'/('d+)/i);
// Make sure to validate the result, as it might not
// match for a given alternative url.
var number = match ? match[1] : false;
alert(number);