Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

363
Visualizações
How to get first URL contain in a string with JavaScript (Nodejs)?

In Node.js I have a string like below but i don't know how to get first URL contain inside that string:

"

<p> You left when I believed you would stay. You left my side when i needed you the most</p>**<img src="https://cloud-image.domain-name.com/storage/images/2021/picture_01.png" />** <br/> <p>Today, I don't have any bad words for you. I just want to thank you</p> **<img src="https://cloud-image.domain-name.com/storage/images/2021/picture_02.jpg" />

I want to get one result:

https://cloud-image.domain-name.com/storage/images/2021/picture_01.png
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This is a bit of a workaround, however, you can scan the string you get

var matches = string.match(/\bhttps?:\/\/\S+/gi);

then just do matches[0], however a few things work around this so alternatively, you could use a library such as URL Knife if you want a robust method with a library.

https://github.com/Andrew-Kang-G/url-knife

about 4 years ago · Juan Pablo Isaza Relatório

0

The indexOf() method returns the index of the first occurrence. You can learn more about string methods on w3schools

const a = `<p> You left when I believed you would stay. You left my side when i needed you the most</p>**<img src="https://cloud-image.domain-name.com/storage/images/2021/picture_01.png" />** <br/> <p>Today, I don't have any bad words for you. I just want to thank you</p> **<img src="https://cloud-image.domain-name.com/storage/images/2021/picture_02.jpg" />`

const start=a.indexOf("https") //To get the index of the first link. (Returns 104)
const end=a.slice(start).indexOf('" />') //To get the end index of end link (Returns 70)
a.slice(start,start+end) //Returns 'https://cloud-image.domain-name.com/storage/images/2021/picture_01.png'

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda