use strict;
my $str = 'ctrl_interface=/data/misc/wifi/sockets
driver_param=use_p2p_group_interface=1
update_config=1
device_name=P580_ROW
manufacturer=LENOVO
model_name=Lenovo
model_number=Lenov
serial_number=hjhjh7
device_type=10-0050F204-5
os_version=01020300
config_methods=physical_display virtual_push_button
p2p_no_group_iface=1
network={
ssid="test1"
psk="154695"
key_mgmt=WPA-PSK
sim_slot="-1"
imsi="none"
priority=1
}
network={
ssid="SSID2"
psk="test123456"
key_mgmt=WPA-PSK
sim_slot="-1"
imsi="none"
priority=19
}';
my $regex = qr/network=\{\n\s*ssid="(?<ssid>.*)"\n\s*psk="(?<psk>.*)"\n\s*key_mgmt=(?<key_mgmt>.*)\n\s*sim_slot="(?<sim_slot>.*)"\n\s*imsi="(?<imsi>.*)"\n\s*priority=(?<priority>.*)\n}/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
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 Perl, please visit: http://perldoc.perl.org/perlre.html