forum

Home / DeveloperSection / Forums / Regex Expression Special Charaters

Regex Expression Special Charaters

Anonymous User 1954 06-Mar-2014

The code is in C#. If I use in regex simple string the code is working (for example fileName="Test"), but if I use special characters(- ( ) [ ] {} ! . , ` ~ @ # % ; = - + &) appear problems.

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

string pattern = ".*" + 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?


Updated on 06-Mar-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By