Python Regex Match

Aug 9, 2017

Assuming you want determine if a string match a certain pattern, is your best bet. You might think of using re.match, but the use case is more specific as it match the beginning of the string (or the whole string).

import reurl = ""# regex for begins withm ="^https://", url)if m:  print("is https")# regex for middle matchm ="://([\w\d-]+\.)?", url)if m:  print("domain is")# regex for ends withm ="\.html$", url)if m:  print("file extension is html")

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.