const regex = /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}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('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}', 'gm')
const 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
}`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions