BenStirrup
1/4/2019 - 8:27 PM

sequential_params.py

import re

path_pattern = r'http://myblog.com/posts/(\S*)'
param_pattern = r'[^;]+'
regex_path = re.compile(path_pattern)
regex_param = re.compile(param_pattern)

URL = 'http://myblog.com/posts/robert;downey;junior'
match = regex_path.match(URL)

if match:
  params_string = match.group(1)
  print(params_string)
  # robert;downey;junior
  params = regex_param.findall(params_string)
  print(params)
  # ['robert', 'downey', 'junior']