【问题标题】:Regex append a string end of a URL正则表达式附加 URL 的字符串结尾
【发布时间】:2015-09-01 01:37:46
【问题描述】:

我正在使用 Kimono Labs 抓取一堆网站。我想将“/critic-reviews”附加到 url 的末尾和服只允许这种格式的正则表达式 -

/^()(.*?)()$/

我有一堆这种代表性格式的网址 -

http://www.metacritic.com/game/playstation-4/disney-infinity-30-edition

【问题讨论】:

    标签: regex kimono


    【解决方案1】:

    尝试在“修改结果”中添加此功能:

    function transform (data) {
       function add_url(item) {
            item.title.href += "/critic-reviews";
            return item;
        }
         for (var collection in data.results) {
            data.results[collection] = data.results[collection].map(add_url);
        }
    
    
      return data;
    }
    

    【讨论】:

      【解决方案2】:

      这似乎是一种匹配模式?

      http://www.metacritic.com/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)
      

      http://regexone.com/lesson/kleene_operators 为您提供了其工作原理的演练。

      http://www.regextester.com/ 并在那里测试您的正则表达式。

      【讨论】:

      • 你想匹配什么,@GreatestEver? Kimono labs 文档似乎表明您的正则表达式的三个部分与 pre、pattern 和 post 部分匹配。你想匹配什么模式? metacritic.com/ 之后的所有内容?只是最后一个斜线之后的部分? (例如“迪士尼无限 30 版”)?你说的“/critic-reviews”是什么?您如何使用正则表达式将某些内容附加到网址?正则表达式匹配模式,它不会向 url 添加文本。我什至不明白你在问什么。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-01
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      相关资源
      最近更新 更多