Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find all links with specific domain in the text with regex

I have a text with links inside, so I try to match them with regex, but somehow the last step I miss..

Link to regex – https://regex101.com/r/pXzZvA/1

The text:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Some text with many letters and some kind of bla bla text
With links - -https://sub.mydomain.com/products/art-for-selling-1   - another word

-https://sub.mydomain.com/products/art-for-selling-1 
https://sub.mydomain.com/products/art-for-selling-1 

paf paf

pew pew 

sub.mydomain.com/products/art-for-selling-1

Here is the regex I use:

/(?:https?:\/\/)?(?:[^\.]+\.)?sub.mydomain.com(\/.*)$/gm

What do I miss is with all the matches I have match of "https://sub.mydomain.com/products/art-for-selling-1 – another word" with " – another word" together. I need to add space exclusion to the end of the regex.

>Solution :

use: (?:https?:\/\/)?(?:\w+\.)?sub\.mydomain\.com\/(?:\w+-?\/?)+

(?:https?:\/\/) : contain https:// or not (http or https)

(?:\w+\.)? : contain a word follow by . or not

sub\.mydomain\.com\/ : must contain sub.mydomain.com/

(?:\w+-?\/?)+ : contain many forms of abc/abc/abc/.../... or not (and may be contained a - after the word or not)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading