javascript - Using replace to select part of a URL -


hello i'm new javascript , need little regex/replace

i want take url example (url case 1)

http://url.com/_t_lastupdate_2670619?location=50457347

or (url case 2)

http://url.com/_t_2670619

i want select in case just

_t_2680619 

ignore after "?" , before (underscore)t(underscore)

is possible regex/replace? thing managed select numbers with

var _t__and_number = document.url.replace(/[^\d]/g, ''); alert(_t__and_number); 

but doesn't solve problem if there's url case 1

(if first number without (underscore)t(underscore) me lot. thanks

solutions:

onetrickpony/michaelb958:

var _t__and_number = window.location.pathname; alert(_t__and_number); 

ermagana:

var _t__and_number = document.url.replace(/\?.*/g, '').match(/.*\/(.*)/)[1]; alert(_t__and_number); 

as suggested onetrickpony, if url browsing, window.location.pathname yield part of url.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -