I remember answering that :D
https://reddit.com/r/AutoHotkey/comments/pr235m/comment/hdfj8nf/?&context=3
Answer remains the same(-ish), but now covers dp
or gp
and product
if found:
https://i.imgur.com/YVw9NXV.png
I used the old link for reference:
urls := ["https://www.amazon.com/Lenovo-IdeaPad-17IML05-Notebook-81WC0015US/dp/B08FMD9FK5/ref=sr_1_2?dchild=1&qid=1631950075&refinements=p_n_feature_twenty-two_browse-bin%3A23447271011%2Cp_89%3ALenovo%2Cp_36%3A2421890011%2Cp_n_size_browse-bin%3A7817234011%2Cp_n_feature_four_browse-bin%3A2289792011&rnid=676578011&s=pc&sr=1-2"
, "https://www.amazon.com/gp/product/B0713WPGLL/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1"]
for _, url in urls {
RegExMatch(url, "\/[dg]p\/(product\/)?\w+", linkId)
MsgBox 0x40,, % "http://amazon.com" linkId
}
Insert::
AmazonLinkStripper() {
; Debug
; Clipboard := "https://www.amazon.com/Lenovo-IdeaPad-17IML05-Notebook-81WC0015US/dp/B08FMD9FK5/ref=sr_1_2?dchild=1&qid=1631950075&refinements=p_n_feature_twenty-two_browse-bin%3A23447271011%2Cp_89%3ALenovo%2Cp_36%3A2421890011%2Cp_n_size_browse-bin%3A7817234011%2Cp_n_feature_four_browse-bin%3A2289792011&rnid=676578011&s=pc&sr=1-2"
RegExMatch(Clipboard, "(https:\/\/www\.amazon\.com\/)(?:.*\/)(dp\/.*\/)", match)
if (match1 != "https://www.amazon.com/")
return
res := match1 match2
; Debug
MsgBox, 0x40040, A_ThisFunc, "res: " res
return, res
}
Copy your URL, then run this function. This works for the given example. I recommend getting the GetURL() into your code to improve this further.
Edit: Reverted MsgBox from a function back to a native command.