Regular expressions are used for searching and manipulating a large text. A regular expression check the following condition such as

·    To identify substrings that begins with or ends with a pattern of characters.

·    To find all words that begins with a group of character and end with some others characters.

·    Check the occurrence of a string pattern.

·    To modify one or more substrings and return them

It is also know as pattern string. It is the part of strings and it containing two types of characters.

·     Literals

·     and metacharacters


For example

“\bt” which means any word beginnings with t.

Where \b is metacharacter and t is the literals.

We used the namespace System.Text.RegularExpression for regular expression. Such namespace contain number of classes that can be used for searching and matching and modifying a text document. The important classes are

·         Regex

·         MatchCollection

·         Match

How uses these classes in our program
For example
using System; 
using System.Text;
using System.Text.RegularExpressions;
class CheckRegExp
{
    public static void Main()
    {
        string str;
        str = "india,srilanka,nepal,berma";
        Regex reg = new Regex("|,");
        foreach (string s in reg.Split(str))
        Console.WriteLine(s);
        Console.ReadLine();
    }
}

 

  Modified On Sep-18-2014 01:23:54 PM

Leave Comment