2 Answers2

1

You could split it by # then take the first element

const url = 'https://www.tripadvisor.co.uk/ShowUserReviews-g503793-d571919-r748731637-Premier_Inn_Waltham_Abbey_hotel-Waltham_Abbey_Essex_England.html#review748731637'

console.log(url.split('#')[0])

Or use regex to match the specific group

const url = 'https://www.tripadvisor.co.uk/ShowUserReviews-g503793-d571919-r748731637-Premier_Inn_Waltham_Abbey_hotel-Waltham_Abbey_Essex_England.html#review748731637'

const [_, res] = /(.*)#.*/.exec(url)

console.log(res)
hgb123
  • 11,887
  • 3
  • 15
  • 33
1

use String.split()

const url = "https://www.tripadvisor.co.uk/ShowUserReviews-g503793-d571919-r748731637-Premier_Inn_Waltham_Abbey_hotel-Waltham_Abbey_Essex_England.html#review748731637"

firstPartUrl = url.split('#')[0]
Mr. Nun.
  • 735
  • 12
  • 29