C# Reading Regex patterns from an XML file



I have an XML file that contains a large number of regex search patterns:



<Data>
<Expression>Error removing log\. Error: 5</Expression>
</Data>
<Data>
<Expression>Unable to open file C:\\Documents\\Stuff\\Message\.txt</Expression>
</Data>


As you can see, the expressions have already been escaped correctly in my XML file. The problem is, when I deserialize the file into a list of strings and then attempt to use the strings as regex patterns, I notice they have been escaped again. For example, the first expression above is being read as:



"Error removing log\\. Error: 5"


That pattern then fails to find any matches in the file I'm searching through.


Is there a way to read these expressions from the XML file without them being escaped again?


Changing the way the patterns are written in the XML file is not an option, because I do not have control of the file.


No comments:

Post a Comment