javascript - Url parameters extraction -


var results = new regexp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); 

could u please explain exactlly happening in above line of code.

thanks in advance.

  • you create variable name of results scoped execution context.
  • you invoke regexp constructor thereby instantiating object , pass string used regex. have way because can't concatenate regex literals outside data.
  • the regex says match of \, ? or & followed name variable, , literal = , make capturing group of every character besides & or #, 0 or more times.
  • you call exec() method on new regexp object, window.location.href (the current url) argument.
  • the return of assigned results variable.
  • the capturing group's contents (if successful) in results[1].

or

you getting param name :)


Comments

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -