using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"https://www\.amazon\.com(?:/[^/]+)?/[dg]p/([a-zA-Z0-9]{10})";
string input = @"https://www.amazon.com/Mercer-Collective-Reversible-Faux-Leather-Small/dp/B0FYH2DLLR/ref=sr_1_1?ie=UTF8&sr=1-1&qid=1769005210&srs=205709307011&content-id=amzn1.sym.f0071731-e15a-4e45-8136-9db6ef13dd66&pd_rd_w=38d4z&dib=eyJ2IjoiMSJ9.9cZBdzbUw1keg_XBUAeM15nKBleTLr7XtAGrD3tTnPQR_z7zrzRRwc7Itf1hZU-gAz81I3HguoxJAtTgM-gwq11vb1fkGuuEfU8epVM5sw5L7rX8JwLHUn8GuAEZQuX42c1u_b7LRNjoMGM3XsV0ksSHLEoHMtYFvv-GP1VsJ4zAIYHXlWkD0gEqS3E06fHv7tzNrBXw4RwMFm8Si2aD2-NhDdxcCk-zCkyRON6QIhw8RqimztymDy8U4r9EWHHLO7i2_Wdm5mh0UemBhfHInkUtrBIrB8OdHX8ankxS7_4.rP_vwMtZee1y0ghS1SG4-I4ZcA0MGQu0tK-ooldvBNU&rnid=20722812011&dib_tag=se&pd_rd_r=b1d1a80e-e547-4774-b819-cfde1f993011&ASIN=B0FYH2DLLR&_encoding=UTF8&pd_rd_wg=MR2dC&ref_=lx_bd&th=1";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx