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

157
Visualizações
JS - how to replace   in regex for links

I have a regex that replaces the link from the moment http to the occurrence of certain characters in [], I would like to add   to these characters - that is to replace the string with the occurrence of certain characters or a hard space:

"https://test.pl'".replace(/https?:\/\/[^ "'><]+/g," ")

Works fine for the characters mentioned in [], I don't know how to add here &nbsp;

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

You can use

.replace(/https?:\/\/.*?(?:&nbsp;|[ '"><]|$)/g," ")

See the regex demo.

Details:

  • https?:\/\/ - http:// or https://
  • .*? - any zero or more chars other than line break chars as few as possible
  • (?:&nbsp;|[ '"><]|$) - one of the following:
    • &nbsp; - &nbsp; char sequence
    • | - or
    • [ "'><] - a space, ", ', > or < char
    • | - or
    • $ - end of string.

JavaScript demo:

const texts = ["https://test.pl&nbsp;test","https://test.pl'test"];
const re = /https?:\/\/.*?(?:&nbsp;|[ '"><]|$)/g;
for (const s of texts) {
  console.log(s, '=>', s.replace(re, " "));
}

about 4 years ago · Santiago Gelvez 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