+1 vote
in Dot Net by

What are Regular expressions? Search a string using regular expressions?

1 Answer

0 votes
by

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

1static void Main(string[] args)
2{
3string[] languages = { "C#", "Python", "Java" };
4foreach(string s in languages)
5{
6if(System.Text.RegularExpressions.Regex.IsMatch(s,"Python"))
7{
8Console.WriteLine("Match found");
9}
10}
11}

The above example searches for “Python” against the set of inputs from the languages array. 

Related questions

+1 vote
asked Jun 25, 2019 in Dot Net by Venkatshastri
+1 vote
asked Jun 25, 2019 in Dot Net by Venkatshastri
...