There are lines like this:

https://www.ebay.com/itm/1X-Serial-Interface-Board-Module-LCD1602-Address-Changeableyq/152646941014?hash=item238a777956:g:J0YAAOSwcu5UNp~I 

Need to change to this view:

 https://www.ebay.com/itm/152646941014 

What next, how to do?
I can’t overpower these regular expressions. Can it be otherwise?

    3 answers 3

    So, for example:

     var s = 'https://www.ebay.com/itm/1X-Serial-Interface-Board-Module-LCD1602-Address-Changeableyq/152646941014?hash=item238a777956:g:J0YAAOSwcu5UNp~I'; console.log(s.match(/(http.*itm\/)/)[1] + s.match(/\/(\d*)\?/)[1]); 

    • TypeError: Cannot read property '1' of null - izhadapter
    • @izhadapter, apparently you have a very old browser. It even works on mobile. Or you have inserted another link there. - Bharata

    Here, prompted, works:

     var url = "https://www.ebay.com/itm/1X-Serial-Interface-Board-Module-LCD1602-Address-Changeableyq/152646941014?hash=item238a777956:g:J0YAAOSwcu5UNp~I"; url = url.replace(/(itm).+(\/\d+).*/, "$1$2"); console.info(url); 

       var s = 'https://www.ebay.com/itm/1X-Serial-Interface-Board-Module-LCD1602-Address-Changeableyq/152646941014?hash=item238a777956:g:J0YAAOSwcu5UNp~I'; console.log(s.match(/(http.*itm\/)/)[1] + s.match(/\/(\d*)\?/)[1]); 
      It works with this URL but with others not in the console it gives me an error for some reason: TypeError: Cannot read property '1' of null

      Well, it is understandable, there seems to be a binding to the unit, and the links may be different.