Detect wifi format with regex in Kotlin

The snip code below demonstrates how to extract data from WIFI data which from QRCode 

var wifiPattern = "(WIFI:S:)(.{1,32})(;T:)(WPA|WEP)(;P:)(.{1,32})(;;)".toRegex()
if (wifiPattern.matches(value)){}

// Parse
val infoArr = wifiPattern.find(value)?.groups
if (!infoArr.isNullOrEmpty() && infoArr.size == 8) {
    val ssid = infoArr[2]
    val password = infoArr[6]
    val type = infoArr[4]
} 

Leave a Reply

Your email address will not be published.Required fields are marked *