# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"SSR.(....)(.BE.)(\w+)(-1)(\w+)(\/)(\w+).*"
test_str = ("SSR BAGW BE HK1DUBEXT0304H13OCT-1TIMBRELL/TEGAELAMISS.1P/AUTH 23KG\n"
"SSR BAGA BE HK1DUBLON0301H13NOV-1TIMBRELL/TEGAELAMISS.1P/AUTH 23KG\n"
"SSR DOCS BE HK1DUBEXT0204H13DEC-1TIMBRELL/TEGAELAMISS\n"
"SSR PETC BE HK1LONEXT0334H13JAN-1TIMBRELL/TEGAELAMISS\n"
"SSR WCHR BE HK1DUBEXT0204H13DEC-1TIMBRELL/TEGAELAMISS\n"
"SSR BAGW BE HK1DUBLON0301H13NOV-1TIMBRELL/TEGAELAMISS.1P/AUTH 23KG\n"
"BE7351 H 08NOV18MANMXP HK4/11251440\n"
"BE2108R/VS8508Y 11NOV18LHREDI HK10/18202000\n"
"A97351 H 08NOV18MANMXP HK4/11251440")
subst = "\\1-\\5-\\7"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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