使用RegExp查找url中的字符

find characters in a url using RegExp

本文关键字:字符 url RegExp 查找 使用      更新时间:2023-09-26

"/products/watch"

对于上面的字符串,我只是试图匹配反斜杠和它们之间的字符。所以在这种情况下,我只想匹配/products/

使用RegExp做这件事的基本方法是什么?或者我可以使用Jquery

var str = "/products/watch";
var matches = str.match(/'/(.*?)'//);
if (matches) {
    // matches[0] is the full match including slashes "/products/"
    // matches[1] is the chars between the slashes "products"
}

工作演示:http://jsfiddle.net/jfriend00/8AAAE/