0

“/产品/手表”

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

使用 RegExp 执行此操作的基本方法是什么,或者我可以使用 Jquery

4

1 回答 1

0
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/

于 2012-09-12T02:12:35.067 回答