What's the best way to validate that a string is a valid URL path in Python?
I want to avoid maintaining a complex regex if possible.
I have this regex so far but I am looking for alternatives because it does not cover all cases for just the path segment:
def check_valid_path(v):
pattern = r"^\/[-a-z\d_\/]*$"
if not compile(pattern).match(v):
raise ValueError(f"Invalid path: {v}. Must match {pattern}")