import re
regex = re.compile(r"^(?:[^\/]+\/)?([a-zA-Z]+(?:-[a-zA-Z]+)+).*$", flags=re.MULTILINE)
test_str = ("something-something-something/45436534/pd\n"
"something-something-something-something/86787097/pd\n"
"1135/something-something-something-86789/pp\n"
"1125/something-something-something-something-86749/pp")
subst = "\\1"
result = regex.sub(subst, test_str)
if result:
print(result)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html