[javascript] How to get the value from the GET parameters?

Try

url.match(/[?&]c=([^&]*)/)[1]

_x000D_
_x000D_
var url = "www.test.com/t.html?a=1&bc=3&c=m2-m3-m4-m5";_x000D_
_x000D_
c= url.match(/[?&]c=([^&]*)/)[1];_x000D_
_x000D_
console.log(c);
_x000D_
_x000D_
_x000D_

This is improvement of Daniel Sokolowski answer Jun 27 '19. Regexp explanation

  • [?&] first matched character must be ? or & (to omit param like ac=)
  • c= name of parameter with = char at end
  • (...) match in first group
  • [^&]* zero or more characters ( * ) different (^) than &
  • [1] choose first group from array of matches

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to url

What is the difference between URL parameters and query strings? Allow Access-Control-Allow-Origin header using HTML5 fetch API File URL "Not allowed to load local resource" in the Internet Browser Slack URL to open a channel from browser Getting absolute URLs using ASP.NET Core How do I load an HTTP URL with App Transport Security enabled in iOS 9? Adding form action in html in laravel React-router urls don't work when refreshing or writing manually URL for public Amazon S3 bucket How can I append a query parameter to an existing URL?

Examples related to url-parameters

What is the difference between URL parameters and query strings? RestTemplate: How to send URL and query parameters together How can I get query parameters from a URL in Vue.js? How can I get the named parameters from a URL using Flask? How to get a URL parameter in Express? PHP check if url parameter exists Pass Hidden parameters using response.sendRedirect() How to convert URL parameters to a JavaScript object? How to replace url parameter with javascript/jquery? Username and password in https url