parik parik - 5 months ago 12
Python Question

How to check if URL has a numbers or String at the end by Python

I have 2 types of URLS

the first one has numbers at the end of url

the second one:

how can i know my input is like first one or second one?

i tried this:

myURL =
parsed_url = urlparse.urlparse(myURL)
number2, number3 = urlparse.parse_qs(parsed_url.query)["t:ac"][0].split("/")

if ( isinstance( number2, numbers.Number) and isinstance( number3, numbers.Number) ) :
print "first"
else :
print "second"


You can use a regex to check if the url ends with numbers or letters i.e.:

if"\d+$", url):
    # url ends with numbers
if"[a-z]+$", url, re.IGNORECASE):
    # url ends with letters