in reply to Some regex magic

I would use three separate regular expressions rather than trying to use just one more complex one using look-aheads. Also, double-quotes are not metacharacters so need not be escaped.

use strict; use warnings; open my $regFH, q{<}, \ <<'EOD' or die qq{open: << HEREDOC: $!\n}; Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstal +l] "DisplayName"="" "UninstallString"="C:\\PROGRA~1\\CISCOS~1\\VPNCLI~1\\Profiles\\PROGRA~ +1\\CISCOS~1\\VPNCLI~1\\profiles\\UNWISE.EXE C:\\PROGRA~1\\CISCOS~1\\V +PNCLI~1\\Profiles\\PROGRA~1\\CISCOS~1\\VPNCLI~1\\profiles\\INSTALL.LO +G" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstal +l\AddressBook] @="" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstal +l\Adobe SVG Viewer] "DisplayName"="Adobe SVG Viewer 3.0" "DisplayVersion"=" 3.0" "DisplayIcon"="C:\\Program Files\\Common Files\\Adobe\\SVG Viewer 3.0\ +\Uninstall\\SetupRsrc.dll,-200" "VersionMajor"=dword:00000003 "VersionMinor"=dword:00000000 "InstallLocation"="C:\\WINDOWS\\system32\\Adobe\\SVG Viewer 3.0" "UninstallString"="C:\\Program Files\\Common Files\\Adobe\\SVG Viewer +3.0\\Uninstall\\Winstall.exe -u -fC:\\Program Files\\Common Files\\Ad +obe\\SVG Viewer 3.0\\Uninstall\\Install.log" "UninstallDir"="C:\\Program Files\\Common Files\\Adobe\\SVG Viewer 3.0 +\\Uninstall" "Publisher"="Adobe Systems, Inc." "RegCompany"="Adobe Systems Inc" "URLInfoAbout"="http://www.adobe.com/" "URLUpdateInfo"="http://www.adobe.com/svg/main.html" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstal +l\Artemis 7.2.1 ODBC] "NoRemove"=dword:00000001 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstal +l\Standalone] "UninstallString"="C:\\WINDOWS\\IsUninst.exe -f\"C:\\Program Filesone. +isu\"" "DisplayName"="This is-not SHOWING" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstal +l\exampler] "DisplayName"="Example Display Name" "UninstallString"="c:\\applications\\uninst.exe" "DisplayVersion"="v7.5.2" "URLInfoAbout"="http://something.htm" "Publisher"="NOT caught" [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstal +l\Branding] "QuietUninstallString"="Rundll32 IedkCS32.dll,BrandCleanInstallStubs" "RequiresIESysFile"="100.0" EOD { local $/ = q{}; while( <$regFH> ) { next unless m{^\[HKEY}; my $displayName = m{"DisplayName"="([^"]+)} ? do { my $s = $1; $s =~ s{^\s+}{}; $s =~ s{\s+$}{}; $s; } : q{Not found!}; my $displayVersion = m{"DisplayVersion"="([^"]+)} ? do { my $s = $1; $s =~ s{^\s+}{}; $s =~ s{\s+$}{}; $s; } : q{Not found!}; my $publisher = m{"Publisher"="([^"]+)} ? do { my $s = $1; $s =~ s{^\s+}{}; $s =~ s{\s+$}{}; $s; } : q{Not found!}; print qq{Name: $displayName\n}, qq{Version: $displayVersion\n}, qq{Publisher: $publisher\n\n}; } } close $regFH or die qq{close: << HEREDOC: $!\n};

The output.

Name: Not found! Version: Not found! Publisher: Not found! Name: Not found! Version: Not found! Publisher: Not found! Name: Adobe SVG Viewer 3.0 Version: 3.0 Publisher: Adobe Systems, Inc. Name: Not found! Version: Not found! Publisher: Not found! Name: This is-not SHOWING Version: Not found! Publisher: Not found! Name: Example Display Name Version: v7.5.2 Publisher: NOT caught Name: Not found! Version: Not found! Publisher: Not found!

I hope this is helpful.

Cheers,

JohnGG

Update: Fixed typo, changed mot to not