====== Python Regular Expressions ====== >>> urls = r'/node/(\d)' >>> regex = re.compile(urls) >>> regex.search('/node/122').group() '/node/1' >>> regex.search('/node/122').group(1) '1' * define the pattern. * compile, python will return regex object * use the search method, pass the string we wanna search for. * match object will be return if the pattern found. * use .group() method of match object to pull out matching group.