Skip to content

Instantly share code, notes, and snippets.

@DVegasa
Forked from error454/gist:3229018
Last active April 18, 2021 16:49
Show Gist options
  • Save DVegasa/248fea16aa1443f5d9a7fcaa1f3b043d to your computer and use it in GitHub Desktop.
Save DVegasa/248fea16aa1443f5d9a7fcaa1f3b043d to your computer and use it in GitHub Desktop.
QR Code WiFi Scheme Regex

QR Code WiFi Scheme Regexs of Extreme Awesomeness

A few regular expressions to parse WIFI schemes such as:

WIFI:T:WEP;S:test;P:rainbows\;unicorns\:jedis\,ninjas\\ secure;;

Network Type

Raw

(?<=T:)[a-zA-Z]+(?=;)

expanded

(?<=T:)       #Match the prefix T: but exclude from capture
    [a-zA-Z]+ #Any alpha character, 1 or more repetitions
(?=;)         #Match the suffix ; but exclude from capture

SSID

Characters that are not allowed

? " $ \ [ ] +

Characters that must be escaped

\ ; , :

Raw

(?<=S:)((?:[^\;\?\"\$\[\\\]\+])|(?:\\[\\;,:]))+(?<!\\;)(?=;)

Java

(?<=S:)((?:[^\\;\\?\\\"\\$\\[\\\\\\]\\+])|(?:\\\\[\\\\;,:]))+(?<!\\\\;)(?=;)

expanded

(?<=S:)                         #Match the prefix S: but exclude from capture
    (                           #Choose from the following 2 choices
        (?:[^\;\?\"\$\[\\\]\+]) #Anything that isn't one of the restricted characters
        |                       #OR
        (?:\\[\\;,:])           #An escaped special character
    )+                          #1 or more repititions
(?<!\\;)(?=;)                   #Match a ; only if there isn't a \; before it

Password

Raw

(?<=P:)((?:\\[\\;,:])|(?:[^;]))+(?<!\\;)(?=;)

Java

(?<=P:)((?:\\\\[\\\\;,:])|(?:[^;]))+(?<!\\\\;)(?=;)

expanded

(?<=P:)                 #Match the prefix S: but exclude from capture
    (                   #Choose from the following 2 choices
        (?:\\[\\;,:])   #An escaped special character
        |               #OR
        (?:[^;])        #Any character that isn't a ;
    )+                  #1 or more repititions
(?<!\\;)(?=;)           #Match a ; only if there isn't a \; before it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment