Users Pricing

forum

Home Forums Regex Expression Special Charaters – MindStick

Regex Expression Special Charaters

Anonymous User 2295 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?


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md