In the System.Text.RegularExpression namespace, there is a regular expression method.
Using System.Collections.Generic;
Using System.Text;
Using System.Text.RegularExpressions;
Namespace Regexdemo
{
Class Program
{
static void Main (string[] args)
{
Regex regex = new Regex ("China", regexoptions.ignorecase);
Use the match method.
String Source = "Mother,my mother is china!";
Match m = regex. Match (source);
if (m.success)
{
Console.WriteLine ("Find first match");
}
Console.WriteLine (New String ('-', 9));
The following example shows a match using the matches method
MatchCollection Matches=regex. Matches (source);
foreach (Match s in matches)
{
if (s.success)
Console.WriteLine ("Found a Match");
}
Console.ReadLine ();
}
}
}
[/code]
Using system.collections.generic;using system.text;using system.text.regularexpressions;namespace URLRegex{ Class program { static void Main (string[] args) { string Pattern = @ "^ (http|https|ftp) \://[a-za-z0-9\ -\.] +\. [A-za-z] {2,3} (: [a-za-z0-9]*)?/? ([a-za-z0-9\-\._\?\,\ '/\\\+&$%\$#\=~]) *$ "; Regex r = new Regex (Pattern); String Source = "Http://www.jb51.net"; Match m = r.match (source); if (m.success) { Console.WriteLine ("URL verified successfully!"); } else { Console.WriteLine ("URL validation failed!"); } Console.ReadLine ();}}}