---
title: "Regex Expression Special Charaters"  
description: "Regex Expression Special Charaters"  
author: "Anonymous User"  
published: 2014-03-06  
updated: 2014-03-06  
canonical: https://www.mindstick.com/forum/1983/regex-expression-special-charaters  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# Regex Expression Special Charaters

The code is in C#. If I use in [regex](https://www.mindstick.com/forum/160352/how-to-use-regex-in-javascript-for-pattern-matching) [simple](https://yourviews.mindstick.com/story/1469/5-simple-ways-to-stay-fit-amp-healthy) string the code is working (for example [fileName](https://www.mindstick.com/interview/23463/difference-between-include-filename-and-include-filename)="Test"), but if I use special [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters)(- ( ) [ ] {} ! . , ` ~ @ # % ; = - + &) appear problems.

fileName = "Test- ( ) [ ] {} ! . , ` ~ @ # % ; = - + &";

[string pattern](https://www.mindstick.com/forum/12883/how-to-extract-sub-string-between-two-string-pattern-using-javascript-jquery) = ".*" + fileName + @"_\d{2}_\d{2}_\d{2}.xml";

//pattert = ".*" + "Test- ( ) [ ] {} ! . , ` ~ @ # % ; = - + &" + @"_\d{2}_\d{2}_\d{2}.xml";

Regex rgx = new Regex(pattern);

if (rgx.IsMatch("..\\"+"Test- ( ) [ ] {} ! . , ` ~ @ # % ; = - + &_13_45_23.xml"))

{

}

There are chances to use these special characters. How can I [resolve this problem](https://answers.mindstick.com/qa/94690/why-does-it-take-google-chrome-so-long-to-open-in-my-computer-what-should-i-do-now-to-resolve-this-problem)?

## Replies

### Reply by Pravesh Singh

Hi Jacob,\

You should use the Regex.Escape method if you want to safely handle special characters in fileName, for example:

```
string pattern = ".*" + Regex.Escape(fileName) +
@"_\d{2}_\d{2}_\d{2}\.xml"; // and don't forget to escape the '.' here ^
```


---

Original Source: https://www.mindstick.com/forum/1983/regex-expression-special-charaters

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
