---
title: "Regular Expressions in C#"  
description: "Regular expressions are used for searching and manipulating a large text. A regular expression check the following condition such asTo identify substr"  
author: "Amit Singh"  
published: 2011-01-18  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/100/regular-expressions-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Regular Expressions in C#

[Regular expressions](https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table) are used for searching and manipulating a large text. A [regular expression](https://www.mindstick.com/articles/11909/java-regex-or-regular-expression-in-java) check the following [condition](https://www.mindstick.com/forum/12711/select-query-with-and-condition) such as

· To [identify](https://www.mindstick.com/forum/159425/java-app-crash-arrayindexoutofboundsexception-identify-invalid-index) substrings that begins with or ends with a pattern of characters.

· To find all words that begins with a group of [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) and end with some others characters.

· Check the occurrence of a [string pattern](https://www.mindstick.com/forum/12883/how-to-extract-sub-string-between-two-string-pattern-using-javascript-jquery).

· 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](https://www.mindstick.com/articles/12552/namespace) System.Text.RegularExpression for regular expression. Such namespace contain number of classes that can be used for searching and [matching](https://www.mindstick.com/forum/162034/what-is-semantic-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();     } }
```

---

Original Source: https://www.mindstick.com/blog/100/regular-expressions-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
