for example, I have:
String a = abcd http//google.com abcd
and
String b=efgh http//yahoomail.hey.com ihklm
How can I extract only the words:
google
yahoomail.hey
TIA
for example, I have:
String a = abcd http//google.com abcd
and
String b=efgh http//yahoomail.hey.com ihklm
How can I extract only the words:
google
yahoomail.hey
TIA
Try this
string pattern = @"//[a-zA-Z0-9]{1,}[.][a-zA-z]{2,4}";
string input = @"http//yahoomail.hey.com ihklm";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine("'{0}'", m.Value.ToString().Replace("/",""));
}
Explaination:
// The match needs to start with "//"
[a-zA-Z0-9]{1,} next there can be any amount of characters specified in[ ] 1 to n times
[.] then there needs to be a .
[a-zA-z]{2,4} the domain can be any Upper/lower character and there need to be at least 2 but max 4 characters
to check your Regexes, i suggest using https://regex101.com/
use the standard settingswith PHP flavour. after you are finished creating the Regex, you can use "Code generator" on the left to convert it to JScript/php/python/c#/java/ruby/rust/perl/golang