I'm trying to match a specific URL(http://www.example.me/area/?si=) that allows me to get value from si. si value will be dynamic
-
1are you trying to get query string value? – Krishna Torque Oct 21 '15 at 15:47
-
or are you trying to check the query string `si` is there or not? – Krishna Torque Oct 21 '15 at 15:48
-
he said "that allows me to get the value from the si" – bflemi3 Oct 21 '15 at 16:01
-
At least own up to your downvote. Please explain. – bflemi3 Oct 21 '15 at 16:34
-
Check [how-to-get-the-value-from-the-url-parameter](http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-url-parameter) which you've pretty much duplicated. – SamWhan Oct 21 '15 at 16:41
3 Answers
Assuming that the value of the si
key in the query string will always be digits (ie: 0 - 9), try this...
var url = 'http://www.example.me/area/?test=4894&si=4077765&f=fjjjf',
si = url.match(/.*[\?&]si=(\d+)/i)[1];
or a little more generic...
function getQueryStringValue(url, key) {
var regex = new RegExp('.*[\\?&]' + key + '=(\\d+)', 'i');
return url.match(regex)[1];
}
if not digits try this...
/.*[\?&]si=(\w+)/i
Explanation:
- .* matches any character (except newline) between 0 and unlimited times
- [\?&] match a single character, either ? or &
- si= matches the characters si= literally (case insensitive)
- (\d+) first capturing group. matches any digit [0-9] between 1 and unlimitted times
- i modifier - case insensitive

- 6,698
- 20
- 88
- 155
-
Without an explanation of the regex, this answer is worthless. Please fix. – ndugger Oct 21 '15 at 15:50
Get any query string value
function qstr(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return false;
}
Check Query String Exists
function isset_qstr(field) {
var url = vp_furl();
if (url.indexOf('?' + field + '=') != -1) {
return true;
} else if (url.indexOf('&' + field + '=') != -1) {
return true;
}
return false;
}
I think you need the first function. Vote up if you think its helpful.
Thank you. Good Luck

- 623
- 1
- 7
- 17
Something like that can do the trick I think:
var regex = /http\:\/\/www\.example\.me\/area\/\?si=(\w*)/;
var url = 'http://www.example.me/area/?si=4077765';
var si = url.match(regex)[1]; // si = '4077765'
The first part of the regex is simply your URL "\" is used to escape special characters.
(\d+) is a capturing group that matches all character from a-z, A-Z, 0-9, including the _ (underscore) character from 0 to n iteration.

- 583
- 7
- 26
-
1why the downvote? Who is downvoting everything without an explanation? – bflemi3 Oct 22 '15 at 13:43