标签: javascript regex
是否可以在JavaScript中使用正则表达式来匹配字符串但只返回匹配的一部分?
例如,在字符串匹配collections/electronics/products中,但仅返回electronics
collections/electronics/products
electronics
https://website.com/collections/electronics/products/some-product
这是我到目前为止所做的:
/(\/collections\/)(.*?)(\/products\/)/ig