Home > DeveloperSection > Blogs > Regular Expressions in C#

Regular Expressions in C#

C# C# 
1 Comment(s)
 3122  View(s)
Rate this:

Regular Expressions

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))







By Samuel Fernandes on   2 months ago

It was really helpful to read this post.

Don't want to miss updates? Please click the below button!

Follow MindStick