代码之家  ›  专栏  ›  技术社区  ›  tomatito

regexp url javascript和in vue

  •  0
  • tomatito  · 技术社区  · 6 年前

    我有这种类型的网址:

    http://localhost:8000/#/requests/5b0ac09ba8abbc6ef5238403/blue
    http://localhost:8000/#/requests/5b0ac09ba8abbc6ef5238402/red
    http://localhost:8000/#/requests/5b0ac09ba8abbc6ef5238403/pink

    我想知道一个url来检查这类url:

    我在尝试类似的东西:

    if (str.match(/^([a-z0-9]{24,})$/)) {
        alert("match!");
    }
    

    但我需要检查完整的url来检查 currentUrl 是这种类型还是另一种类型。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Julien METRAL    6 年前

    你可以试试这样的方法:

    if ((new RegExp('\#\/(?:requests)\/([0-9a-z]+)\/(?:[a-z]+)$','g')).test(str)) {
        alert('match!');
    }