.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

Regex in Web.config?

Hey guys,

I have to save some application-wide regular expressions. I'm not able to save these string values in the Web.config appsettings because the regex values have special characters (like double-quotes), which make it difficult to save them as XML strings.

Is there a way to work-around this, or maybe store the regex values elsewhere, so that they are available application-wide and can be edited easily without compiling the code.

Any thoughts?
Wednesday, April 16, 2008
It seems a bit strange that you'd want a regular expression to change often enough that you'd want it in a config file.

Your best bet is probably to store them in a database, and expose them for edit through an admin interface.
Bennor McCarthy Send private email
Wednesday, April 16, 2008
It should be possible to encode them, before storing them in web.config.
ColinM Send private email
Wednesday, April 16, 2008
You could encode it.... but you can avoid the issue by putting these "configurable regular expressions" in a plain old text file (eg old school ini files).  You can cache the expressions and update the cache via a cache dependency on that file.
Giovanni Galbo
Wednesday, April 16, 2008
These are the characters you have to escape in your regex:

& = &
< = &lt;
> = &gt;
" = &quot;
' = &apos;

Unfortunately, you can't use CDATA in an attribute in your appSettings section.

Wednesday, April 16, 2008
Thanks guys! Encoded values work just fine.
Wednesday, April 16, 2008

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz