import re
regex = re.compile(r"(?(?=The following software are installed on the remote host :\s+))(?<software>[^\[]+)\[version\s(?<version>[^\]]+)\]")
test_str = ("\"20811\",\"\",\"\",\"None\",\"182.56.44.12\",\"tcp\",\"445\",\"Microsoft Windows Installed Software Enumeration (credentialed check)\",\"It is possible to enumerate installed software.\",\"This plugin lists software potentially installed on the remote host by\n"
" crawling the registry entries in :\n"
" \n"
" HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\n"
" HKLM\\SOFTWARE\\Microsoft\\Updates\n"
" \n"
" Note that these entries do not necessarily mean the applications are\n"
" actually installed on the remote host - they may have been left behind\n"
" by uninstallers, or the associated files may have been manually\n"
" removed.\",\"Remove any applications that are not compliant with your organization's\n"
" acceptable use and security policies.\",\"\",\"\n"
" The following software are installed on the remote host :\n"
" \n"
" 7-Zip 15.12 (x64) [version 15.12]\n"
" Rapid Recovery Agent [version 6.1.3.100]\n"
" JXplorer [version 3.3.1]\n"
" System Center Endpoint Protection [version 4.10.207.0] [installed on 2016/10/26]\n"
" Notepad++ [version 6.8.8]\n"
" WinPcap 4.1.3 [version 4.1.0.2980]\n"
" Wireshark 2.2.4 (64-bit) [version 2.2.4]\n"
" Windows Firewall Configuration Provider [version 1.2.3412.0] [installed on 2015/11/20]\n"
" Microsoft Visual C++ 2013 x86 Minimum Runtime - 12.0.21005 [version 12.0.21005] [installed on 2015/11/20]\n"
" Microsoft Visual C++ 2010 x64 Redistributable - 10.0.40219 [version 10.0.40219] [installed on 2015/12/17]\n"
" Microsoft Visual C++ 2013 x64 Additional Runtime - 12.0.40649 [version 12.0.40649] [installed on 2017/01/26]\n"
" Java 7 Update 79 (64-bit) [version 7.0.790] [installed on 2015/12/14]\n"
" Configuration Manager Client [version 5.00.8239.1000] [installed on 2018/03/28]\n"
" Microsoft Visual C++ 2013 Redistributable (x64) - 12.0.40649 [version 12.0.40649.5]\n"
" Microsoft Endpoint Protection Management Components [version 4.10.0207.0] [installed on 2016/10/26]\n"
" Java SE Development Kit 7 Update 79 (64-bit) [version 1.7.0.790] [installed on 2015/12/14]\n"
" Microsoft Visual C++ 2005 Redistributable [version 8.0.61001] [installed on 2015/12/17]\n"
" Microsoft Visual C++ 2013 Redistributable (x64) - 12.0.21005 [version 12.0.21005.1]\n"
" AppRecovery Agent [version 6.1.3.100] [installed on 2018/03/18]\n"
" Microsoft Silverlight [version 5.1.30514.0] [installed on 2015/11/20]\n"
" Microsoft Policy Platform [version 1.2.3602.0] [installed on 2015/11/20]\n"
" Microsoft Forefront Endpoint Protection 2010 Server Management [version 4.10.0207.0] [installed on 2016/10/26]\n"
" Microsoft Visual C++ 2013 x64 Minimum Runtime - 12.0.40649 [version 12.0.40649] [installed on 2017/01/26]\n"
" Microsoft Security Client [version 4.10.0207.0] [installed on 2016/10/26]\n"
" Microsoft SQL Server System CLR Types (x64) [version 10.51.2500.0] [installed on 2015/12/17]\n"
" Microsoft SQL Server 2008 R2 Management Objects (x64) [version 10.51.2500.0] [installed on 2015/12/17]\n"
" Microsoft Visual C++ 2010 x86 Redistributable - 10.0.40219 [version 10.0.40219] [installed on 2015/12/17]\n"
" Microsoft Visual C++ 2013 x86 Additional Runtime - 12.0.21005 [version 12.0.21005] [installed on 2015/11/20]\n"
" Microsoft Visual C++ 2005 Redistributable (x64) [version 8.0.61000] [installed on 2015/11/20]\n"
" Microsoft Visual C++ 2013 Redistributable (x86) - 12.0.21005 [version 12.0.21005.1]\n"
" \"")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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