$re = '/(?<wholekey>(?s)^\[.*?\].*?(?=^\[|\z))/m';
$str = 'Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE]
"ServiceLastKnownStatus"=dword:00000002
[HKEY_LOCAL_MACHINE\\BCD00000000]
[HKEY_CURRENT_USER\\AppEvents\\Schemes\\Apps\\.Default\\Notification.Default\\.Current]
@="C:\\\\Windows\\\\media\\\\Windows Notify System Generic.wav"
[HKEY_LOCAL_MACHINE\\BCD00000000\\Description]
"KeyName"="BCD00000000"
"TreatAsSystem"=dword:00000001
"GuidCache"=hex:f4,60,9c,00,7b,c3,da,01,03,27,00,00,8a,d6,94,57,42,4c,7f,29,8a,\\
00,00,00
"Element"=hex:00
"Element"=hex(7):7b,00,37,00,65,00,61,00,32,00,65,00,31,00,61,00,63,00,2d,00,\\
32,00,65,00,36,00,31,00,2d,00,34,00,37,00,32,00,38,00,2d,00,61,00,61,00,61,\\
00,33,00,2d,00,38,00,39,00,36,00,64,00,39,00,64,00,30,00,61,00,39,00,66,00,\\
30,00,65,00,7d,00,00,00,00,00
"Type"=dword:101fffff
"Element"="EFI PXE 0 for IPv4 (74-5D-22-21-B1-95) "
"OSMaxVersionTested"=hex(b):00,00,ff,3f,00,00,0a,00
"OSMinVersion"=hex(b):00,00,00,00,00,00,0a,00
"WMP11.AssocFile.3G2"=hex(0):
"Drivers"=hex(100000):
"DriverType"=hex(200000):
"lParam"=hex(4):00,00,00,00,00,00,00,00
[HKEY_LOCAL_MACHINE\\BCD00000000\\Objects\\{3edef9e6-2f6e-11ef-968a-9457424c7f29}\\Elements]
[HKEY_LOCAL_MACHINE\\BCD00000000\\Objects\\{3edef9e9-2f6e-11ef-968a-9457424c7f29}]
"command"=hex(2):22,00,25,00,70,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,\\
69,00,6c,00,65,00,73,00,25,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,\\
00,20,00,4d,00,61,00,69,00,6c,00,5c,00,57,00,61,00,62,00,2e,00,65,00,78,00,\\
65,00,22,00,20,00,2f,00,43,00,72,00,65,00,61,00,74,00,65,00,43,00,6f,00,6e,\\
00,74,00,61,00,63,00,74,00,20,00,22,00,25,00,31,00,22,00,00,00
"PrimaryLineOutTopo"=hex(40007):41,00,70,00,6f,00,50,00,72,00,65,00,73,00,65,\\
00,74,00,31,00,00,00,00,00
"Element"=hex(7):7b,00,31,00,61,00,66,00,61,00,39,00,63,00,34,00,39,00,2d,00,\\
31,00,36,00,61,00,62,00,2d,00,34,00,61,00,35,00,63,00,2d,00,39,00,30,00,31,\\
00,62,00,2d,00,32,00,31,00,32,00,38,00,30,00,32,00,64,00,61,00,39,00,34,00,\\
36,00,30,00,7d,00,00,00,00,00
"Isa"=hex(8):01,00,00,00,01,00,00,00,00,00,00,00,00,00,00,00,28,00,00,00,01,01,\\
00,00,00,00,00,00,00,00,00,00,00,01,00,00,01,03,00,00,e8,42,00,00,00,00,00,\\
00,08,00,00,00,01,03,00,00,e8,4a,00,00,00,00,00,00,08,00,00,00,01,03,00,00,\\
e8,82,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,86,00,00,00,00,00,00,08,\\
00,00,00,01,03,00,00,e8,8a,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,8e,\\
00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,92,00,00,00,00,00,00,08,00,00,\\
00,01,03,00,00,e8,96,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,9a,00,00,\\
00,00,00,00,08,00,00,00,01,03,00,00,e8,9e,00,00,00,00,00,00,08,00,00,00,01,\\
03,00,00,e8,a2,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,a6,00,00,00,00,\\
00,00,08,00,00,00,01,03,00,00,e8,aa,00,00,00,00,00,00,08,00,00,00,01,03,00,\\
00,e8,ae,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,b6,00,00,00,00,00,00,\\
08,00,00,00,01,03,00,00,e8,ba,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,\\
be,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,c2,00,00,00,00,00,00,08,00,\\
00,00,01,03,00,00,e8,c6,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,ca,00,\\
00,00,00,00,00,08,00,00,00,01,03,00,00,e8,ce,00,00,00,00,00,00,08,00,00,00,\\
01,03,00,00,e8,d2,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,d6,00,00,00,\\
00,00,00,08,00,00,00,01,03,00,00,e8,da,00,00,00,00,00,00,08,00,00,00,01,03,\\
00,00,e8,de,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,e2,00,00,00,00,00,\\
00,08,00,00,00,01,03,00,00,e8,e6,00,00,00,00,00,00,08,00,00,00,01,03,00,00,\\
e8,ea,00,00,00,00,00,00,08,00,00,00,01,03,00,00,e8,ee,00,00,00,00,00,00,08,\\
00,00,00,01,03,00,00,ee,f6,00,00,00,00,00,00,02,00,00,00,01,03,00,00,ee,fa,\\
00,00,00,00,00,00,02,00,00,00,01,03,00,00,ee,fe,00,00,00,00,00,00,02,00,00,\\
00,02,03,00,00,03,00,00,00,03,00,00,00,ff,ff,ff,ff,02,03,00,00,04,00,00,00,\\
04,00,00,00,ff,ff,ff,ff,02,03,00,00,0e,00,00,00,0e,00,00,00,ff,ff,ff,ff,02,\\
03,00,00,06,00,00,00,06,00,00,00,ff,ff,ff,ff,02,03,00,00,0c,00,00,00,0c,00,\\
00,00,ff,ff,ff,ff,02,03,00,00,01,00,00,00,01,00,00,00,ff,ff,ff,ff,03,03,00,\\
00,ff,ff,bf,ff,00,00,00,00,00,00,40,00
"Configuration Data"=hex(9):ff,ff,ff,ff,ff,ff,ff,ff,00,00,00,00,02,00,00,00,05,\\
00,00,00,0c,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,ff,ff,ff,ff,\\
00,00,ff,ff,01,00,05,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\\
00
"Pci"=hex(a):e8,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\\
00,00,00,00,00,00,01,00,00,00,01,00,01,00,0e,00,00,00,00,01,00,00,00,00,00,\\
00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,00,00,ff,ff,ff,ff,00,00,00,00,\\
08,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,05,00,00,00,00,00,00,ff,\\
ff,00,00,00,00,00,00,08,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,40,01,\\
00,00,00,00,00,00,7f,01,00,00,00,00,00,00,08,01,00,00,00,00,00,00,00,00,00,\\
00,00,00,00,00,00,02,00,00,00,00,00,00,ff,02,00,00,00,00,00,00,08,01,00,00,\\
00,00,00,00,00,00,00,00,00,00,00,00,00,03,00,00,00,00,00,00,6f,03,00,00,00,\\
00,00,00,08,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,78,03,00,00,00,00,\\
00,00,7a,03,00,00,00,00,00,00,08,01,00,00,00,00,00,00,00,00,00,00,00,00,00,\\
00,e8,02,00,00,00,00,00,00,ff,02,00,00,00,00,00,00,08,01,00,00,00,00,00,00,\\
00,00,00,00,00,00,00,00,f0,01,00,00,00,00,00,00,f8,01,00,00,00,00,00,00,08,\\
01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,b0,03,00,00,00,00,00,00,cf,03,\\
00,00,00,00,00,00,08,01,00,00,00,00,00,00,00,00,00,00,00,00,00,00,e8,03,00,\\
00,00,00,00,00,ff,03,00,00,00,00,00,00,08,01,00,00,00,00,00,00,00,00,00,00,\\
00,00,00,00,ce,01,00,00,00,00,00,00,cf,01,00,00,00,00,00,00,08,01,00,00,00,\\
00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,00,00,00,ff,03,00,00,00,00,\\
00,00,00,03,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,10,00,00,00,00,\\
00,ff,ff,ff,ff,ff,ff,ff,ff,08,03,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\\
00,00,08,00,00,00,00,00,ff,ff,0d,00,00,00,00,00';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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 PHP, please visit: http://php.net/manual/en/ref.pcre.php