简体   繁体   中英

regular expression, extract substring from path

Doing this in javascript.

I have path's like this: /p/BC3eKD-rX-w/

I have a pattern like this: /\\/p\\/([\\w-]+)\\//g

I am trying to extract "BC3eKD-rX-w" but it keeps matching the entire string.

I suck at regular expressions, have spent 2 hours reading and watching videos and am very frustrated.

Help?

var exp = /\/p\/([\w-]+)\//g;
console.log(exp.exec("/p/BC3eKD-rX-w/")[1]);

Works fine with me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM