Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

300
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda