javascript - getURLParameter and RegExp -


i new jquery , javascript. trying understand piece of code below. can explain me parameter "name" suppose be? url? (i.e https://stackoverflow.com/questions/ask). can explain how location.search.match.regexp("[?|&]" + name + '=(.+?)(&|$)')) works. great if can use in example input "name" , display output.

thank in advance!

 $(document).ready(function () {       function geturlparameter(name) {           return decodeuricomponent(          (location.search.match(regexp("[?|&]" + name + '=(.+?)(&|$)')) || [, null])[1]);       }   } 

name called function's parameter. when function called uses parameter search query string portion of browser's url parameter matching name , returns value. query string specified (at minimum): ?parameter1=value1 number of additional/optional parameters separated &, ie. ?parameter1=value1&parameter2=value2. if name parameter not found, function returns null.

as regular expression, used search query string mentioned above. looks either "?" or "&" followed name followed "=" , 1 or more of characters. [] treats every character inside literally. | standard or operator. throws value of 1 or more characters capture group (by wrapping part of regex in parenthesis). last bit ensures either end of string after value or there "&" proceeding (most followed query parameter , value). when function returns [1] returning second value in match result array above mentioned capture group, or name parameter's value (or null if no match found).


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -