Categories

Jun 25, 2019 in Dot Net

Q:

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

1 Answer

Jun 25, 2019

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)
2 {
3 string[] languages = { "C#", "Python", "Java" };
4 foreach(string s in languages)
5 {
6 if(System.Text.RegularExpressions.Regex.IsMatch(s,"Python"))
7 {
8 Console.WriteLine("Match found");
9 }
10 }
11 }

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

Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

Madanswer
Jun 25, 2019 in Dot Net
Jun 25, 2019 in Dot Net
Jun 25, 2019 in Dot Net
...