user3451476 user3451476 - 5 months ago 44
Java Question

Regex matching in python 2.7

I am new to Python and would like to know how to have build a regex pattern to match a URL

I have the following code in Java and it works. I need to have a similar one in python


URI uri = new URI("http://localhost:8080")

Matcher m = Pattern.compile("(.*)" + "/client" + "/([0-9]+)")

Could someone guide me with having an equivalent regex in Python


Here's the equivalent in Python 2.7:

import re
from urlparse import urlparse

url = urlparse('http://localhost:8080')

match = re.match(r'(.*)/client/([0-9]+)', url.path)


Here's how you would use match to get the individual components (just guessing as to what you want to do next):

if match:
    prefix =
    client_id = int(