473,473 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

REGEX to change multiple XML Date Values

a
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:
"<periodOfReport>2006-08-08Z</periodOfReport><transactionDate><value>2006-07-01Z</value></transactionDate><signatureDate>2006-09-01Z</signatureDate>";
Oct 17 '06 #1
3 2346
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

Oct 17 '06 #2
a
Marc:

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

Paul

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

"Marc Gravell" wrote:
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

Oct 17 '06 #3
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?
"a" wrote:
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:
"<periodOfReport>2006-08-08Z</periodOfReport><transactionDate><value>2006-07-01Z</value></transactionDate><signatureDate>2006-09-01Z</signatureDate>";
Jan 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Yatima | last post by:
Hey Folks, I've got some info in a bunch of files that kind of looks like so: Gibberish 53 MoreGarbage 12 RelevantInfo1 10/10/04
4
by: Chuck Haeberle | last post by:
I have an interesting regular expression challenge for someone more experienced with them than I for a data layer class... I need an expression to search a SQL statement (any type, SELECT INSERT...
8
by: rjb | last post by:
Hi! Could somebody have a look and help me to optimize the code below. It may look like very bad way of coding, but this stuff is very, very new for me. I've included just few lines. Regex...
0
by: shmulik28 | last post by:
I'm just getting my feet wet w/regex's and was wondering if someone could show me how to parse a piece of code. I'm screen scraping from a financial website and want to add the values into an...
10
by: Chance Hopkins | last post by:
I'm trying to match a set of matches after some initial text: mytext: "something" "somethingelse" "another thing" "maybe another" (?:mytext: )(?<mymatch>{1,1}+{1,1}+)+ I only get the last one...
4
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the...
11
by: jarod1701 | last post by:
Hi, i'm currently trying to replace an unknown string using regular expressions. For example I have: user_pref("network.proxy.http", "server1") What do I have to do to replace the...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
5
by: shapper | last post by:
Hello, What is the Regex expression to validate a date time format as follows: dd-mm-yyyy hh:mm:ss An example: 20-10-2008 10:32:45
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.