this is what I use
If RegExMatch(Clipboard, "amazon\.([a-z.]+/).*(([dg]p|product)/([A-Z0-9]{10}))",link_)
Clipboard := "smile.amazon." . link_1 . link_2
result: smile.amazon.com/dp/B07JZTBV9C
It’s hard with an age gap, but this seems to be very popular. It’s technically ages 7 and up (it was created based on a 7 yr olds idea!)
Taco vs Burrito - The Wildly Popular Surprisingly Strategic Card Game Created by a 7 Year Old https://smile.amazon.com/dp/B07JZTBV9C/ref=cm_sw_r_cp_api_glt_fabc_6YC97H9T41QQKFZ63M3F?_encoding=UTF8&psc=1
Oooo... I have enjoyed Tasker for a awhile. :) I did ask here in this subreddit sometime earlier this year about stripping + reconstructing an AMAZON URL down to:
amazon.com/dp/B07JZTBV9C
I have come up with a couple different macros using different software, but they did work consistently. :( Anyway, the folks here were not able to come up with the a RegEx that worked the way I wanted. I had shelved this project for the time being, but now you inspire me to try again!
The one possible RegEx appears to be: (/dp/|/gp)([A-Z0-9]{10})
UPDATE: I have come to use: (http.://)([a-z].+.com/).+(dp/|gp/|product/)([A-Z0-9]+)
as this allows me to capture the site address, too!
This works in the following:
JavaScript, Python (3.4), Ruby (2.1), Java (JDK 14), MySQL 8.0 (beta)
But NOT:
PHP (7)
Good luck! :)
Just a quickie... Send {F6}^c
seems very browser-specific, mostly for older browsers. ^l
(CTRL+L) changes the active focus to the address bar, even in Windows Explorer. So maybe a Send, ^l^a^c
to copy the URL contents to the Clipboard?
consider the following:
... with your provided RegEx
, the product description still remains and should be stripped alongside anything after the 10-character product ID.
this is what the result should resemble:
https://www.amazon.com/dp/B07JZTBV9C
In case you are interested in another approach and assuming that those urls have fixed data positions, here is a non-regex solution:
OriginalURL := "https://www.amazon.com/Taco-Burrito-Popular-Surprisingly-Strategic/dp/B07JZTBV9C/?_encoding=UTF8&pd_rd_w=kJDyA&pf_rd_p=3bfeb04e-703a-461f-b489-780480465c8a&pf_rd_r=T0F0410TSNH60D3Y6QWH&pd_rd_r=bf7a94f6-0f9f-412d-b04a-83b36174e008&pd_rd_wg=iSWZB&ref_=pd_gw_unk"
Template := "{1}//{3}/{5}/{6}"
MsgBox, % Format(Template, StrSplit(OriginalURL, "/")*)
return
; Output: https://www.amazon.com/dp/B07JZTBV9C
Well, does CTRL+L work just as well in those instances? Just wondering.
The RegEx I found that works is the following:
(http.://)([a-z].+.com/).+(dp/|gp/|product/)([A-Z0-9]+)
$1 : https://
$2 : www.amazon.com
$3 : /dp
$4 : /B083ZQYHBC
substitution : $1$2$3$4
result : https://www.amazon.com/dp/B07JZTBV9C
However, I cannot figure out how to do that in one step. So I broke up the RegEx between two lines:
InStr(Clipboard, "amazon") ? RegExMatch(Clipboard, "(http.://)([a-z].+.com/)", var1)
InStr(Clipboard, "amazon") ? RegExMatch(Clipboard, "(dp/|gp/|product/)([A-Z0-9]+)", var2)
Clipboard := var1 var2
MsgBox, 4161, status?, % Clipboard
The original Amazon URL:
Works perfectly. Thank you!!!
The result gives smile.amazon.com/dp/B07JZTBV9C
. What would I need to edit so the result give https://smile.amazon.com/dp/B07JZTBV9C
(or https://www.amazon.com/dp/B07JZTBV9C
)? I do use Smile with Amazon, but not everyone does. Your code seems to take out the https://
...may I ask why?