Fri, 17 May 2024


C# Regular expressions: Example of creation of Groups and using Group classes

By: Peter, NetArt Media
Wed, 15 July 2020

string strText="212.56.87.23 netartmedia.net";

Regex oRegex=new Regex(@"(?<IP_ADDRESS>(d|.)+)s"+@"(?<URL>S+)");

MatchCollection oMatchCollection=oRegex.Matches(strText);

foreach(Match oMatch in oMatchCollection)
{

Console.WriteLine("IP: "+oMatch.Groups["IP_ADDRESS"]);
Console.WriteLine("URL: "+oMatch.Groups["URL"]);
}

/*
*
will print to the screen

IP: 212.56.87.23
URL: netartmedia.net

*/


Category: Web Development
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox