I have a URL as follows
http://localhost:8080/list/PEPPR_BDCAREUGWJ
I need "PEPPR_BDCAREUGWJ" from this url. How to do this by javascript?
I have a URL as follows
http://localhost:8080/list/PEPPR_BDCAREUGWJ
I need "PEPPR_BDCAREUGWJ" from this url. How to do this by javascript?
You can use split()
and get the last value from array.
let str = 'http://localhost:8080/list/PEPPR_BDCAREUGWJ'
let res = str.split('/').pop()
console.log(res)
Another way can be using lastIndexOf()
and slice()
let str = 'http://localhost:8080/list/PEPPR_BDCAREUGWJ'
let res = str.slice(str.lastIndexOf('/')+1)
console.log(res)
You can also use regular expression.
let str = 'http://localhost:8080/list/PEPPR_BDCAREUGWJ'
let res = /\/[^\/]+$/.exec(str)[0].slice(1)
console.log(res)
Just split by slash(/
) using String#split
method and get last part from the array using Array#pop
method.
let str = 'http://localhost:8080/list/PEPPR_BDCAREUGWJ'
let res = str.split('/').pop();
console.log(res)