I've a url and a regex. I want to check whether the url matches the regex or not.
I'm checking it on Amazon product urls. Amazon Product URLs have dp
in their urls. For eg:-
https://www.amazon.in/product-slug/dp/B07655JJYT
https://www.amazon.in/product-slug/some/path/dp/B00W9E8O80/ref?query_param=value
https://www.amazon.in/dp/B00W9E8O80/
I want to match all the above-given type of URLs.
Below is my code:-
import re
url = 'https://www.amazon.in/Perfect-Pricee-Cupcake-Steel-Muffin/dp/B07655JJYT'
pattern = "^*://www.amazon.in/*/dp/*$"
if re.search(pattern, url):
print(1)
I'm not well versed with regexes. Not sure why it throws an error.