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)
or (url case 2)
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
Post a Comment