I have a delimited string similar to this line:
l | l | l | l | l | l | l | l | l | oldDate | l | whether |
I want to replace the contents of the 10th section with a new date. I can match the old date with 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 cannot figure out how to undo this group with new text. I tried:
pipeRegEx.Replace(strMessage, "$4", newDate) 'where newDate is a string var
But this returns the original message since the 4th group could not be found. I cannot replace a string with a matching date, because there are several dates in the string (orderDate, receivedDate, etc.) And it can be matched by one of them.
Does anyone know how to replace this text?
Thanks in advance for your help.
source share