First, we will have to remove the IP address using the regex. Then You can use PHP and simply explode the string ` and get your JSON from the resulting array.
$var = '192.168.1.1 | SUCCESS => { "architecture": "amd64", "lsbdistcodename": "wheezy", "lsbdistdescription": "Debian GNU/Linux 7.9 (wheezy)", "lsbdistid": "Debian", "lsbdistrelease": "7.9", "lsbmajdistrelease": "7", "lsbminordistrelease": "9", "memoryfree": "653.05 MB", "memoryfree_mb": "653.05", "memorysize": "1002.94 MB", "memorysize_mb": "1002.94", "operatingsystem": "Debian", "operatingsystemmajrelease": "7", "operatingsystemrelease": "7.9", "os": { "family": "Debian", "lsb": { "distcodename": "wheezy", "distdescription": "Debian GNU/Linux 7.9 (wheezy)", "distid": "Debian", "distrelease": "7.9", "majdistrelease": "7", "minordistrelease": "9" }, "name": "Debian", "release": { "full": "7.9", "major": "7", "minor": "9" } }, "osfamily": "Debian", "partitions": { "sda1": { "filesystem": "LVM2_member", "size": "41938944" } }, "physicalprocessorcount": 1, "processor0": "Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz", "processorcount": 1, "processors": { "count": 1, "models": [ "Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz" ], "physicalcount": 1 }, "timezone": "EET", "uniqueid": "007f0101", "uptime": "360 days", "uptime_days": 360, "uptime_hours": 8644, "uptime_seconds": 31119057, "virtual": "vmware"}192.168.1.1 | SUCCESS => { "architecture": "x86_64", "is_virtual": true, "kernel": "Linux", "kernelmajversion": "3.10", "kernelrelease": "3.10.0-514.2.2.el7.x86_64", "kernelversion": "3.10.0", "macaddress": "00:50:56:b1:c6:49", "macaddress_eno16777984": "00:50:56:b1:c6:49", "memoryfree": "1.58 GB", "memoryfree_mb": "1617.09", "memorysize": "1.80 GB", "operatingsystemmajrelease": "7", "operatingsystemrelease": "7.3.1611", "os": { "family": "RedHat", "name": "CentOS", "release": { "full": "7.3.1611", "major": "7", "minor": "3" } }, "osfamily": "RedHat", "partitions": { "sda1": { "filesystem": "xfs", "mount": "/boot", "size": "1024000", "uuid": "e50a313f-98fa-4d7d-a40d-eb0c3b5f3ef5" }, "sda2": { "filesystem": "LVM2_member", "size": "30423040" } }, "path": "/usr/local/bin:/usr/bin", "physicalprocessorcount": 1, "processor0": "Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz", "processorcount": 1, "processors": { "count": 1, "models": [ "Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz" ], "physicalcount": 1 }, "timezone": "EET", "uniqueid": "44d40600", "uptime": "87 days", "uptime_days": 87, "uptime_hours": 2094, "uptime_seconds": 7539660, "virtual": "vmware"';
$pattern = '/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:\/\d{2})?/';
$replacement = '';
$result = preg_replace($pattern, $replacement, $var); // Remove the IP address
echo "$result".PHP_EOL;
$arr = explode("| SUCCESS =>", $result); //Explode the string by the constant string
print_r($arr);
Resulting Array
The first element will be empty.
Array
(
[0] =>
[1] => { "architecture": "amd64", "lsbdistcodename": "wheezy", "lsbdistdescription": "Debian GNU/Linux 7.9 (wheezy)", "lsbdistid": "Debian", "lsbdistrelease": "7.9", "lsbmajdistrelease": "7", "lsbminordistrelease": "9", "memoryfree": "653.05 MB", "memoryfree_mb": "653.05", "memorysize": "1002.94 MB", "memorysize_mb": "1002.94", "operatingsystem": "Debian", "operatingsystemmajrelease": "7", "operatingsystemrelease": "7.9", "os": { "family": "Debian", "lsb": { "distcodename": "wheezy", "distdescription": "Debian GNU/Linux 7.9 (wheezy)", "distid": "Debian", "distrelease": "7.9", "majdistrelease": "7", "minordistrelease": "9" }, "name": "Debian", "release": { "full": "7.9", "major": "7", "minor": "9" } }, "osfamily": "Debian", "partitions": { "sda1": { "filesystem": "LVM2_member", "size": "41938944" } }, "physicalprocessorcount": 1, "processor0": "Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz", "processorcount": 1, "processors": { "count": 1, "models": [ "Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz" ], "physicalcount": 1 }, "timezone": "EET", "uniqueid": "007f0101", "uptime": "360 days", "uptime_days": 360, "uptime_hours": 8644, "uptime_seconds": 31119057, "virtual": "vmware"}
[2] => { "architecture": "x86_64", "is_virtual": true, "kernel": "Linux", "kernelmajversion": "3.10", "kernelrelease": "3.10.0-514.2.2.el7.x86_64", "kernelversion": "3.10.0", "macaddress": "00:50:56:b1:c6:49", "macaddress_eno16777984": "00:50:56:b1:c6:49", "memoryfree": "1.58 GB", "memoryfree_mb": "1617.09", "memorysize": "1.80 GB", "operatingsystemmajrelease": "7", "operatingsystemrelease": "7.3.1611", "os": { "family": "RedHat", "name": "CentOS", "release": { "full": "7.3.1611", "major": "7", "minor": "3" } }, "osfamily": "RedHat", "partitions": { "sda1": { "filesystem": "xfs", "mount": "/boot", "size": "1024000", "uuid": "e50a313f-98fa-4d7d-a40d-eb0c3b5f3ef5" }, "sda2": { "filesystem": "LVM2_member", "size": "30423040" } }, "path": "/usr/local/bin:/usr/bin", "physicalprocessorcount": 1, "processor0": "Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz", "processorcount": 1, "processors": { "count": 1, "models": [ "Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz" ], "physicalcount": 1 }, "timezone": "EET", "uniqueid": "44d40600", "uptime": "87 days", "uptime_days": 87, "uptime_hours": 2094, "uptime_seconds": 7539660, "virtual": "vmware"
)
Note : This regex is for IPV4 addresses that I got from IPV4 regex. You can change the regex for removing the IPV6 addresses too.
Working IDEONE Link