T
tshad
I have a text string that has a date in it and I am trying to pull out the
date. In my earlier posts I got a couple of patterns that seem correct, but
I can't seem to get them to work. I want to account for 1 or 2 digits in
the month and day fields and 2 or 4 in the year field.
After not getting the correct result I put it down to the simplest pattern
which would match exactly the number of digits and I get nothing.
For example, if I have the following string:
valueIn = "At 02/23/2007 DOM";
I want to end up with 02/23/2007.
If I use:
Match oMatch;
oMatch = Regex.Match(valueIn, @"\d{2}/\d{2}/\d{4}");
I get nothing from my oMatch.Groups[1].Value.
If I have:
oMatch = Regex.Match(valueIn, @"\d{1,2}/\d{1,2}/\d{2,4}");
strValue = oMatch.Groups[1].Value;
I get nothing from my oMatch.Groups[1].Value;
If I have:
oMatch = Regex.Match(valueIn,
@"\d{1,2}(-|/)\d{1,2}(-|/)(\d{2}|\d{4})");
strValue = oMatch.Groups[1].Value;
oMatch.Groups[1].Value = "/"
oMatch.Groups[2].Value = "/"
oMatch.Groups[3].Value = "20"
What is happening here?
I would have expected the 1st one to work which I assume says look for a
pattern of: 2 digits, a slash, 2 more digits, another slass and 4 digits
which is in this string.
Not sure why it found the slashes and the 20 in the last set up.
Thanks,
Tom
date. In my earlier posts I got a couple of patterns that seem correct, but
I can't seem to get them to work. I want to account for 1 or 2 digits in
the month and day fields and 2 or 4 in the year field.
After not getting the correct result I put it down to the simplest pattern
which would match exactly the number of digits and I get nothing.
For example, if I have the following string:
valueIn = "At 02/23/2007 DOM";
I want to end up with 02/23/2007.
If I use:
Match oMatch;
oMatch = Regex.Match(valueIn, @"\d{2}/\d{2}/\d{4}");
I get nothing from my oMatch.Groups[1].Value.
If I have:
oMatch = Regex.Match(valueIn, @"\d{1,2}/\d{1,2}/\d{2,4}");
strValue = oMatch.Groups[1].Value;
I get nothing from my oMatch.Groups[1].Value;
If I have:
oMatch = Regex.Match(valueIn,
@"\d{1,2}(-|/)\d{1,2}(-|/)(\d{2}|\d{4})");
strValue = oMatch.Groups[1].Value;
oMatch.Groups[1].Value = "/"
oMatch.Groups[2].Value = "/"
oMatch.Groups[3].Value = "20"
What is happening here?
I would have expected the 1st one to work which I assume says look for a
pattern of: 2 digits, a slash, 2 more digits, another slass and 4 digits
which is in this string.
Not sure why it found the slashes and the 20 in the last set up.
Thanks,
Tom