![](/img/trans.png)
[英]extract strings between last two slashes using regular expression in javascript
[英]Regular Expression to find value between slashes
我一直在嘗試尋找2個正斜杠之間的值。 該值可以是xx/a/xx
, xx/ab/xx
或xx/c/xx
我只想獲取這兩個斜杠之間的值,“ xx”可以是任何字符,因為這是網址中路徑名的一部分。 這是我到目前為止的內容,但是沒有用。
var pathname = window.location.pathname;
var match = pathname.match(/\/(\w+)\//i)
您實際上並不需要正則表達式,請使用split
:
var s = 'xx/ab/xx'
var r = s.split('/')[1];
//=> ab
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.