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.
Dear User, We are grateful for your interest in the Kodingwindow Android app. We intend to soon make it available on the Google Play Store. Currently, Android versions 10 and up require manual apk installations. Would you like to get the app?