孤芳又自赏

文章 评论 浏览 30

孤芳又自赏 2022-05-04 13:45:54
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");
});

第 105 题:编程题 匹配查找特定字符串

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文