Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Regex and strings from app.config

Tags:

c#

.net

asp.net

I am trying to read regex from app.config file

if I try to read strings it is working fine but, if I try to get the regex Pattern it is not accepting my pattern

Here my code is

<appSettings>
<add key="regex" value=@"^(?<TicketNum>\w{3}-\d+)\s+(?<Message>.+?)$"></add>
<add key="getString" value="siva"/>;
</appSettings>

Am I missed anything?

like image 611
Sivamohan Reddy Avatar asked Feb 04 '23 19:02

Sivamohan Reddy


1 Answers

You need to escape < and > in your xml, try this:

<appSettings>
    <add key="regex" value="^(?&lt;TicketNum&gt;\w{3}-\d+)\s+(?&lt;Message&gt;.+?)$"/>
</appSettings>

Escaping XML Data. Here:

enter image description here

Also no need for the @ sign.

like image 61
Sadique Avatar answered Feb 13 '23 02:02

Sadique