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.

  • .match(/\/(\d+)/)[1] - Mike
  • @Mike, thanks, this is what you need! - Eugene

1 answer 1

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) }()); 

  • one
    From http://site.com/12345#abc/6789 pull out 6789 regex101.com/r/tTXR3c/1 - Visman
  • @Visman, oh, I counted - fixed :) - Yuri