C# program to demonstrate the use of regular expressions
Program.cs
usingSystem.Text.RegularExpressions;Console.WriteLine("———————————————————————————————————————————");Console.WriteLine("C# program for the regular expressions");Console.WriteLine("———————————————————————————————————————————");strings="ABC DEF 123 456 789";Matchm=Regex.Match(s,@"\d+");if(m.Success){Console.WriteLine(m.Value);Console.WriteLine("Value "+m.Value);Console.WriteLine("Length "+m.Length);Console.WriteLine("Index "+m.Index);}else{Console.WriteLine("Not Matched");}if(Regex.IsMatch(s,"abc..",RegexOptions.IgnoreCase)){Console.WriteLine("Matched");}else{Console.WriteLine("Not Matched");}Console.WriteLine(IsValid("Hello 123456789"));Console.WriteLine(IsValid(":)"));Console.WriteLine("———————————————————————————————————————————");staticboolIsValid(strings){returnRegex.IsMatch(s,@"^[a-zA-Z0-9 ]*$");}
Output
kodingwindow@kw:~/csharp$ dotnet run
———————————————————————————————————————————
C# program for the regular expressions
———————————————————————————————————————————
123
Value 123
Length 3
Index 8
Matched
True
False
———————————————————————————————————————————
kodingwindow@kw:~/csharp$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.