The essence of what, I make an extension for chrome, he needs to process the address of the open page. The site structure is as follows: http://site.com/12345 http://site.com/raz/dva/12345 You need to pull out the numbers 12345, but one more condition before the # sign, because possible link with an anchor. Those. the condition sounds like "all the digits from the sign / to #" I think we need to do regexp, but did not work with it at all. Please help me figure it out.
1 answer
Link to the article on regular expressions: http://javascript.ru/regexp
(function() { var href = 'http://site.com/link/12345#якорь'; // Наша псевдоссылка // Регулярное выражение для это ссылки var reg = href.replace(/^https?\:\/\/site\.com[^#?]*\/(\d+)\#?.*$/, '$1'); console.log(reg) }()); - oneFrom
http://site.com/12345#abc/6789pull out6789regex101.com/r/tTXR3c/1 - Visman - @Visman, oh, I counted - fixed :) - Yuri
|
.match(/\/(\d+)/)[1]- Mike