$re = '/name\[(?<policy_name>[\w\.\-\d\s]+)\]uuid\[(?<uuid>[\w\d\.\-\s]+)\]srcintf\[(?<source_interface>[\w\.\-\s\d]+)\]dstintf\[(?<destination_interface>[\w\d\-\.\s]+)\]srcaddr\[(?<source_address>[\w\d\.\-\s]+)\]dstaddr\[(?<destination_address>[\w\d\.\-\s]+)\]action\[(?<policy_action>\w+)\]schedule\[(?<policy_schedule>[\w\d\s\.\-]+)\]service\[(?<policy_services>[\w\s\.\d\-]+)\](utm-status\[(?<utm_status>[\w\s\.\-\d]+)\])?logtraffic\[(?<log_traffic>[\d\w\s\.\-]+)\]ippool\[(?<pool_status>[\s\w\d\.\-]+)\]poolname\[(?<pool_name>[\w\s\d\.\-]+)\](profile-protocol-options\[(?<protocol_options>[\w\s\d\.\-]+)\]ssl-ssh-profile\[(?<ssl_ssh_profile>[\w\d\.\s\-]+)\]ips-sensor\[(?<ips_sensor>[\w\d\s\.\-]+)\])?nat\[(?<nat_status>[\w\d\s\.\-]+)\]/m';
$str = 'name[BDC-OMNIChannel-Server-OUT]uuid[260b133c-6dfc-51eb-d0a5-eff41f9c9cea]srcintf[INT-To-CoreWAN TO-FG3700-DC-IC]dstintf[SERVICE-INT-OUTSIDE]srcaddr[Omni-Channel-Testbed]dstaddr[all]action[accept]schedule[always]service[DNS HTTP HTTPS PING]utm-status[enable]logtraffic[all]ippool[enable]poolname[INTERNET-SERVICES-OUTBOUND-POOL]profile-protocol-options[default]ssl-ssh-profile[certificate-inspection]ips-sensor[high_security]nat[enable]';
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