I have a pipe delimited string like this:
blah|blah|blah|blah|blah|blah|blah|blah|blah|oldDate|blah|blah|
I would like replace the content of the 10th section with a new Date. I am able to match the the old date with the the following code:
'create a group with the first 9 non-pipes followed by a pipe, a group with the old date followed by a pipe, and sub-group of just the old date.
Dim pipeRegEx As New RegularExpressions.Regex("(([^\|]*\|){9})(([^\|]*)\|)")
'the sub-group is the 4th group ordinal in the match GroupCollection
Dim oldDate as String=pipeRegEx.Match(strMessage).Groups(4).Value
However, I can't figure out how to repace that group with new text. I have tried:
pipeRegEx.Replace(strMessage, "$4", newDate) 'where newDate is a string var
But that returns the original message like it was unable to find the 4th group. I am unable to do a string replace with the matched date since there are multiple dates in the string (orderDate, receivedDate, etc) and its possible to match on one of those by accident.
Does anyone know how to replace this text?
Thanks in advance for any help.