all groups > c# > october 2006 >
You're in the

c#

group:

REGEX to change multiple XML Date Values


REGEX to change multiple XML Date Values a
10/16/2006 8:19:01 PM
c#: In the example below, I'm trying to simply find all the date values in an XML
document (the XML is a string in this example) and then add an upper case Z
between the last digit and the closing '<' character. My strSearch is ok,
but my strReplace doesn't seem to do anything.

Anyone know how to get my desired result?

Thanks,

Paul
-------------------------------------------------------------

string saTests1 =
"<periodOfReport>2006-08-08</periodOfReport><transactionDate><value>2006-07-01</value></transactionDate><signatureDate>2006-09-01</signatureDate>";
string strSearch =
">(?<Year>(?:\\d{4}))-(?<Month>\\d{2})-(?<Day>\\d{2})<";
string strReplace = ">${year}-${month}-${day}Z<";

Regex.Replace( saTests1, strSearch, strReplace );

Desired output:
Re: REGEX to change multiple XML Date Values Marc Gravell
10/16/2006 10:11:47 PM
a: you didn't name the sections, so $year etc don't exist
b: you need to capture the returned string

string strReplace = ">${1}-${2}-${3}Z<";
string result = Regex.Replace(saTests1, strSearch, strReplace);

Marc
Re: REGEX to change multiple XML Date Values a
10/16/2006 11:06:01 PM
Marc:

I thought that I did name the sections...thanks for pointing that out to me.

Paul

-------------------------------------------------------

[quoted text, click to view]
RE: REGEX to change multiple XML Date Values sbparsons
1/26/2007 2:16:01 AM
It looks to me like you have named them too... (?<NAME>etc...)

The only thing I can see is that your names start with uppercase letters in
the regex, but not so in the Replace string - is it case sensitive I wonder?


[quoted text, click to view]
AddThis Social Bookmark Button