Sølve Tornøe Sølve Tornøe - 4 months ago 18
jQuery Question

Extract Multiple Values from string regex

I have the string:

"BSSID:00:00:00:00:00:00<br>Encryption: WPA+PSK WPA+AES-CCM<br>Channel: 11<br><br>Current Clients: <br><br><br>"


I cannot figure out how to use regex to filter out the value of "BSSID", "encryption" and so on.
I have tried this regex:
\b(BSSID:|Encryption: |Channel: )\b

However, this does not work as thought. If someone could head me to the right direction, that would be great! Thanks.

Answer

Use the following regex with String.replace function:

var str = "BSSID:00:00:00:00:00:00<br>Encryption: WPA+PSK WPA+AES-CCM<br>Channel: 11<br><br>Current Clients: <br><br><br>",
    replaced = str.replace(/\b(BSSID|Encryption|Channel)\s?:/g, "");

console.log(replaced);  // 00:00:00:00:00:00<br> WPA+PSK WPA+AES-CCM<br> 11<br><br>Current Clients: <br><br><br>