Search code examples
regexgoogle-analytics

How do I write regex for an order ID link?


I have the following link https://events.mypage.com/orders/5r69dhhhsx/iz1ngvs53/

While https://events.mypage.eu/orders/ is always the same, /5r69dy6hsx/iz1nap5s53/will always differ, but with the same pattern of small letters and numbers. I need it for Google Analytics URL match. How can I write it?

My current version where I tried it looks like this:

https://events.mypage.com/orders/([a-z][0-9])/([a-z][0-9])/


Solution

  • Forward slashes in the regex should be escaped. Using ([a-z][0-9]) will match only when there is a single smallcase character followed by a single digit number. To match multiple characters and numbers you can use ([a-z0-9]+). If you know the exact length or range of length of the ([a-z0-9]+) part, you can use quantifiers such as ([a-z0-9]{exact length}) or ([a-z0-9]{lower limit, upper limit}) repectively. Try this: https?:\/\/events\.mypage\.com\/orders\/([a-z0-9]+)\/([a-z0-9]+)\/