in Javascript i tried to read window.location.search. value of this variable could be something like ?ref=somestring&read=1 or ?read=1&ref=sometring or just ?ref=somestring.
how to extract only ref=somestring from the variable?
so far i tried the following regex:
ref.match(/ref=([^\&].*)\&/) // works when ?ref=somestring&read=1
ref.match(/ref=([^\&].*)\&/) // not working when only ?ref=somestring
ref.match(/ref=([^\&].*)\&?/) // works when ?ref=somestring
ref.match(/ref=([^\&].*)\&?/) // works but took all part if ?ref=somestring&read=1