Greatest Ever
Greatest Ever

Reputation: 11

Regex append a string end of a URL

I am using Kimono Labs to scrape a bunch of websites. I'd like to append "/critic-reviews" to the end of a url Kimono allows regex only in this format -

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

I have a bunch of URLs in this representative format -

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

Upvotes: 0

Views: 750

Answers (2)

bem
bem

Reputation: 11

Try to add this function in "Modify results" :

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;
}

Upvotes: 1

Shih-Min Lee
Shih-Min Lee

Reputation: 9700

this seems to be one matching pattern?

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

http://regexone.com/lesson/kleene_operators gives you a walkthrough of how this works.

http://www.regextester.com/ and test your regex up there.

Upvotes: 0

Related Questions