Is there a way to remove anything after # from this URL in Javascript
            Asked
            
        
        
            Active
            
        
            Viewed 44 times
        
    2 Answers
2
            
            
        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
        
- 13,869
- 3
- 20
- 38
2
            
            
        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.
        
- 775
- 11
- 29
