Extract ASIN from URL

Extract ASIN from URL

How to extracting the 10-digit product code (also known as ASIN, Amazon Standard Identification Number) from an Amazon product URL.

```=REGEXEXTRACT(A2, "\/dp\/([a-zA-Z0-9]{10})\/?")
```

Here's the explanation for each part of the formula:

• `=REGEXEXTRACT(A2, "\/dp\/([a-zA-Z0-9]{10})\/?")`
• `REGEXEXTRACT`: This function is used to extract specific portions from a text string based on a regular expression pattern.
• `A2`: This cell contains the Amazon URL.
• `\/dp\/`: This part of the regular expression is used to match the `/dp/` string, which usually precedes the ASIN code in the URL.
• `([a-zA-Z0-9]{10})`: This part is used to match any 10-character long string made up of letters and numbers. This represents the ASIN code.
• `\/?`: This part indicates that the URL may end with a slash, but it is not mandatory.

Overall, this formula extracts the 10-digit ASIN code from the Amazon URL in cell A2.

It's important to note that `REGEXEXTRACT` is a function in Google Sheets[1], not a built-in function in Microsoft Excel. If you are using Excel, this formula will not work. Alternatively, achieving the same functionality in Excel is more complicated and may require the use of VBA (Visual Basic for Applications) or other methods.

JavaScript approach

```const url = 'https://www.amazon.com/dp/B07X51T2VK';
const asin = url.match(/\/([A-Z0-9]{10})(?:[/?]|\$)/)[1];
console.log(asin);
```