javascript - Parse text and get value -


i have many links:

var 1 = '/news/local/edit?user=marcus&owner=ffff'; var 2 = '/news/other/edit?user=josh&owner=ddd'; var 3 = '/news/local/edit?user=john'; var 4 = '/news/local/test/marcus/edit?owner=aaaa&user=ady'; 

how can these links value of user?

this should return:

one = 'marcus'; 2 = 'josh'; 3 = 'john'; 4 = 'ady'; 

the result can in array.

you can use regular expression extract query string parameters. please refer below question.

how can query string values in javascript?

sample fiddle

related code answer edited according context here:

function getparameterbyname(name,url) {     name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");     var regex = new regexp("[\\?&]" + name + "=([^&#]*)"),         results = regex.exec(url);     return results == null ? "" : decodeuricomponent(results[1].replace(/\+/g, " ")); }  var 1 = '/news/local/edit?user=marcus&owner=ffff'; var 2 = '/news/other/edit?user=josh&owner=ddd'; var 3 = '/news/local/edit?user=john'; var 4 = '/news/local/test/marcus/edit?user=ady&owner=aaaa';  alert(getparameterbyname("user",one)); alert(getparameterbyname("user",two)); alert(getparameterbyname("user",three)); alert(getparameterbyname("user",four));  

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -