how to Extract Link part from a string in javascript

Advertisements

Having a string of the below structure how can i extract only the link portion of it.
https://qr.1688.com/s/OaPpTrzR CZ0736

https://qr.1688.com/s/2Q8NXya1 CZ3050

const getShortUrl = (string)  =>{
    let query = string.trim().replaceAll('"', '');
    if(query.indexOf('https://qr') >= 0){
          return query.substring(query.indexOf('https://qr'));
        
    }
  }


But the above code return something like `https://qr.1688.com/s/2Q8NXya1 CZ3050` but what i wanted is something like this `https://qr.1688.com/s/2Q8NXya1`

how can i extrract this portion of string.

>Solution :

You can use split:

return query.split(' ')?.[0];

Leave a ReplyCancel reply