how to Extract Link part from a string in javascript


Having a string of the below structure how can i extract only the link portion of it. CZ0736 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 ` CZ3050` but what i wanted is something like this ``

how can i extrract this portion of string.

>Solution :

You can use split:

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

Leave a Reply Cancel reply