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

306
Visualizações
Regex for capturing all the urls in a paragraph except for a specific domain

I need to capture all the urls in a paragraph apart from the urls from a specific domain/ sub domain.For example in the below paragraph I need to capture all the urls apart from example.com

"This is a paragraph name.url.com it contains random urls name-dev.url.com name-qa.url.com www.example.com test.example.com http://TestCaSeSensetivEUrl.com http://www.test.com https://www.example.com test.com"

Urls I need to capture

  • name.url.com
  • name-dev.url.com
  • name-qa.url.com
  • http://TestCaSeSensetivEUrl.com
  • http://www.test.com
  • test.com

Urls I don't need to capture as below

  • www.example.com

  • test.example.com

  • https://www.example.com

I have tried the below regex using negative look behind method, but it's not working as I need.

/(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?([a-z0-9]+(?<!example)[\-\.]{1}[a-z0-9+]+(?<!example)\.[a-z]{2,5})/gi

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This should be sufficient for your use case:

/(?<!\S)(?:https?:\/\/)?(?:(?:(?!example)\w+[.-])+[a-z]{2,11})(?!\S)/gi

See https://regex101.com/r/NdOxKt/1 for a demonstration of the regex at work. Below is a rough explanation of what the regex is doing:

  • The leading and trailing (?<!\S) essentially splits the string into segments on space characters, including whitespace and newlines
  • The ?: syntax makes each set of parenthesis it is in a non-capture group, saving memory on the machine where it is ran and speeding up your execution time
  • (?:https?:\/\/)? optionally matches both http and https for URLs without matching the invalid characters : and / anywhere else in the URL
  • (?:(?!example)\w+[.-])+ looks for one or more words that do not match example, followed by either a hyphen or a period
  • [a-z]{2,11} matches the final domain extension, i.e. com, org, or enterprises
about 4 years ago · Juan Pablo Isaza Relatório

0

this could be a solution

^(https?:\/\/)?(?!(?:www\.)?google\.*)([\da-zA-Z.-]+)\.([a-zA-Z\.]{2,6})([\/\w .-]*)*\/?$

for example here google is excluded from being captured

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