Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

307
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!