文章 评论 浏览 30
const urls = [ "https://www.xx.cn/api?keyword=&level1=&local_batch_id=&elective=&local_province_id=33", "https://www.xx.cn/api?keyword=&level1=&local_batch_id=&elective=800&local_province_id=33", "https://www.xx.cn/api?keyword=&level1=&local_batch_id=&elective=800,700&local_province_id=33", ]; function getElective(url) { const reg = new RegExp("(^|&)elective=([^&]*)(&|$)", "i"); const r = url.substr(1).match(reg); if (r != null) { return r[2] ? r[2].split(",") : []; } return []; } urls.forEach((url) => { const result = getElective(url); console.log(result, "---result"); });
文章 0 评论 0
接受
第 105 题:编程题 匹配查找特定字符串