Regular expression is a template to match a set of input. The pattern can consist of operators, constructs or character literals. Regex is used for string parsing and replacing the character string.
For Example:
* matches the preceding character zero or more times. So, a*b regex is equivalent to b, ab, aab, aaab and so on.
Searching a string using Regex
1 | static void Main(string[] args) |
3 | string[] languages = { "C#", "Python", "Java" }; |
4 | foreach(string s in languages) |
6 | if(System.Text.RegularExpressions.Regex.IsMatch(s,"Python")) |
8 | Console.WriteLine("Match found"); |
The above example searches for “Python” against the set of inputs from the languages array.