By 19/12/2013 2 Comments

Search Text with Regular Expression C# Code Example

Regular Expression:

  • a regular expression (abbreviated regex or regexp) is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. “find and replace”-like operations. The concept arose in the 1950, when the American mathematician Stephen Kleene formalized the description of a regular language, and came into common use with the Unix text processing utilities ed, an editor, and grep (global regular expression print), a filter
  • It is useful for validation on the websites, it force the end-user to enter the correct or valid information (e.g) a valid phone number, an email, name and much more etc

Following example which uses regular expression in c#

string str = "We few, we happy few, we band of brothers..."; // initialize a string

Regex reg = new Regex("we"); // create an object of Regex class and pass 1 parameter from constructor

MatchCollection matchcoll = reg.Matches(str); // assign method into another object

foreach (Match matchVar in matchcoll) // loop through each value
Console.WriteLine("{0} at position {1}", // print the result
matchVar.Value.Trim(), matchVar.Index); // call a method

Next Tutorial →

Posted in: C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .