Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.
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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use split:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading