Regex for Affiliate URL

157 Views Asked by At

For Matomo outgoing link tracking I need the regex pattern, which matched the following URLs: https://www.example.com/product/?sku=12345&utm_source=123456789

and

https://www.example.com/product/?utm_source=123456789

"https://www.example.com/" and "utm_source=123456789" are always fixed in the URL, just "product/" or "category/product/" change and must replaced by regex pattern.

Thanks

1

There are 1 best solutions below

0
Ricardo Valente On

Maybe this example can help you reach your goal:

(?<=https:\/\/www\.example\.com\/).+(?=utm_source=123456789)

It looks for any characters between these two groups:

  • https://www.example.com/
  • utm_source=123456789

Given the examples:

  • https://www.example.com/product/?sku=12345&utm_source=123456789
  • https://www.example.com/product/?utm_source=123456789

Your matches would be:

  • product/?sku=12345&
  • product/?