javascript - Getting dynamic value from URL -


i tried multiple ways splits, substrings value of employeeid below, there effective regex way?

/api/getvalue;id=12345;age:25;employeeid=4?test=true&othervalues=test 

i want employee id value 4

any appreciated

you use simple regular expression match on employeeid:

// extract employeeid regex var employeeid = url.match(/;employeeid=(\d+)/, url)[1];  console.log(employeeid);  >>> 4 

or if you'd function value can selected use following:

function getvalue(url, name) {     var m = new regexp(';' + name + '[=:](\\d+)', 'g').exec(url);     if (m) {         return m[1];     }     return ''; }  var age = getvalue(     '/api/getvalue;id=12345;age:25;employeeid=4?test=true&othervalues=test',      'age'     );  console.log(age);  >>> 25 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -