qretsar qretsar - 2 months ago 6x
C# Question

Isolate https://*something*.com from a bunch of text

I have a :

string BunchOfText
which contains a link which starts with
and ends with
I need to isolate that link and to put it in another string.
Any suggestions how?
My text looks like this:

It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Why do we use it?

I want to have a new string

string link ="https://mydomain/RANDOMGENERATEDTEXT.com"

By the time of this edit, user : serhiyb, gave me a perfect answer!

Regex linkParser = new Regex(@"https:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.com\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
string rawString = "some text with https://go.com link in it";
foreach(Match m in linkParser.Matches(rawString))

Live demo: https://dotnetfiddle.net/Zg8UDj

It will find all links that start with https and are subdomain of .com zone.