How to Extract only numeric value only from the URL javascript or jquery -


have url's has numeric value in it. need extract numeric value. numeric value position not constant in url. need generic way how extract. can't use split method because position of value not constant.

for example:

1. https:// www.example.com/a/1234567/b/d?index.html 2. http://www.example.com/a?index.html/pd=1234567 3. http://www.example.com/a/b/c/1234567?index.html 

so above 3 url's has numeric value position not constant. can please provide generic method can expected output "1234567".

use basic regular expression:

"http://www.example.com/a?index.html/pd=1234567".match( /\d+/ ); 

this returns first series of numbers in string. in above case, following:

[ "1234567" ] 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -