我在试着弄到一些亚马逊的商品我发现了一个模式:ASIN总是在“/dp/”之后如何从该字符串中提取ASIN(b003cp0v6s)?
我在用鲁比
url = "http://www.amazon.it/Calvin-Klein-Deluxe-K0S21120--Orologio/dp/B003CP0V6S/ref=lp_1597641031_1_8?ie=UTF8&qid=1349983393&sr=1-8"
最佳答案
str = "http://www.amazon.it/Calvin-Klein-Deluxe-K0S21120--Orologio/dp/B003CP0V6S/ref=lp_1597641031_1_8?ie=UTF8&qid=1349983393&sr=1-8"
(match = str.match(/\/dp\/([^\/]*)/)) && match[1]
# => "B003CP0V6S"
关于ruby - ruby 正则表达式是什么以获得该URL的特定部分?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12847316/