import re
regex = re.compile(r"^(.*?)\.((?:\.?[0-9]+){3,}(?:[-a-z]+)?)\.nupkg$", flags=re.MULTILINE)
test_str = ("knockoutjs.3.4.2.nupkg\n"
"log4net.2.0.8.nupkg\n"
"runtime.tizen.4.0.0-armel.microsoft.netcore.jit.2.0.0.nupkg\n"
"nuget.core.2.7.0-alpha.nupkg\n"
"microsoft.identitymodel.6.1.7600.16394.nupkg\n\n"
"Package: knockoutjs Version: 3.4.2\n"
"Package: log4net Version: 2.0.8\n"
"Package: runtime.tizen.4.0.0-armel.microsoft.netcore.jit Version: 2.0.0\n"
"Package: nuget.core Version: 2.7.0-alpha\n"
"Package: microsoft.identitymodel Version: 6.1.7600.16394\n")
subst = "Package: \\1 Version: \\2"
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