I don't know if this is possible with MyCode, but imagine how useful this would be - to automatically convert any Amazon link in a post to a better-looking link with affiliate info added.
This is a typical amazon link:
When someone pastes the link in a post, mMyBB automatically converts it to this:
http://www.amazon.com/Baby-Einstein-Take...pd_sim_t_1
Is it possible to automatically convert it to this:
Baby-Einstein-Take-Along-Tunes
OK, now onto the problem. First, I am simply trying to successfully detect an Amazon.com link and add in the referral code.
Here's what I have so far :
Expression:
Replacement:
This works on most links. The problem I'm looking at is that there are so many ways an Amazon link can look, including some with no descriptors.
Now I'm trying to combine this with another bit of regex to find a valid ASIN and generate a better link. This is to try to fix the few messed-up Amazon link types I have seen that do not work with the above script.
Getting closer...
OK. I have a new version. This one seems to find the ASIN code in some messier Amazon links and builds a new link. the problem is that unlike the one I posted above, it convert a single link, and trim out the other two... trying to figure that problem out.
OK. my code works as a "global" regex replace, but not otherwise. As far as I can tell the forum does not work that way, or I just don't know how to add that feature into my Expression. Any regex experts care to chime in?
This is a typical amazon link:
http://www.amazon.com/Baby-Einstein-Take-Along-Tunes/dp/B000YDDF6O/ref=pd_sim_t_1
When someone pastes the link in a post, mMyBB automatically converts it to this:
<a href="http://www.amazon.com/Baby-Einstein-Take-Along-Tunes/dp/B000YDDF6O/ref=pd_sim_t_1">http://www.amazon.com/Baby-Einstein-Take...pd_sim_t_1</a>
Example:http://www.amazon.com/Baby-Einstein-Take...pd_sim_t_1
Is it possible to automatically convert it to this:
<a href="http://www.amazon.com/dp/B000YDDF6O&tag=your_Associates_ID">Baby-Einstein-Take-Along-Tunes</a>
Example:Baby-Einstein-Take-Along-Tunes
OK, now onto the problem. First, I am simply trying to successfully detect an Amazon.com link and add in the referral code.
Here's what I have so far :
Expression:
<a(.*?)href="http(?:s)?://(?:www\.)?amazon\.com/(.*?)"(.*?)>(.*?)</a>
Replacement:
<a target="_blank" href="http://www.amazon.com/$2&tag=affiliate-20">$4</a>
This works on most links. The problem I'm looking at is that there are so many ways an Amazon link can look, including some with no descriptors.
Now I'm trying to combine this with another bit of regex to find a valid ASIN and generate a better link. This is to try to fix the few messed-up Amazon link types I have seen that do not work with the above script.
Getting closer...
OK. I have a new version. This one seems to find the ASIN code in some messier Amazon links and builds a new link. the problem is that unlike the one I posted above, it convert a single link, and trim out the other two... trying to figure that problem out.
OK. my code works as a "global" regex replace, but not otherwise. As far as I can tell the forum does not work that way, or I just don't know how to add that feature into my Expression. Any regex experts care to chime in?