0

I need some help with URL matching regex. I read the regex syntax documentation but it's so complex.

I'm trying to create a URL list for a checkout funnel, how would I set up regex for the following?

https://shop.mysite.ca/[unique ID]/checkouts/[unique ID 2]
OR
https://shop.mysite.ca/[unique ID]/checkouts/[unique ID
2]?step=contact_information

What I have so far, though not sure how to put the optional parameter "step=contact_information")

/^(https:\/\/shop.mysite.ca\/)([\da-z]+)(\/checkouts\/)([\da-z]+)$/

3 Answers 3

1

You can use a "?" to make a group either appear 0 or 1 times, making it optional.

/^(https:\/\/shop.mysite.ca\/)([\da-z]+)(\/checkouts\/)([\da-z]+)(\?step=contact_information)?$/
Sign up to request clarification or add additional context in comments.

Comments

0

this should work

^(https:\/\/shop.mysite.ca\/)([\da-z]+)(\/checkouts\/)([\da-z]+)((\?step=contact_information)*)$

edit: forgot the ? and used * instead. The other solution by @thomas is a bit better I think

Comments

0

Try it:

^(https:\/\/shop.mysite.ca\/)(\d+.)(\/checkouts)(\/)(\d+.)($|\?\w.+$)

If unique ID is composed with non numbers characteres:

^(https:\/\/shop.mysite.ca\/)([\da-zA-Z]+.)(\/checkouts)(\/)([\da-zA-Z]+.)($|\?\w.+$)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.