Well the regex did do the job in .NET (using $1$3 as replacement) on lists of the indicated type, like:
"42,43" -> "43"
"41,42" -> "41"
"41,42,43" -> "41,43"
That is: "42,15,42,173,42" will be reduced to "15,173", which was basically what I wanted. And yes, "before,42XX,after" will be reduced to "beforeXX,after", but that was not the kind of data I needed to manipulate in this case.
You can try out .NET regexes by installing the
runtime plus a tool like
RegexDesigner.
Update
And you're right: the regex by
reasonablekeith above does the same, but will leave "before,42XX,after" intact (if that's what you want); His regex is shorter tho', and could be preferred for that reason, -- but it is not forgiving with resp. to whitespace around the numbers, ie. "23,42 ,45, 56,42" will be reduced to "23,42 ,45, 56".
Best regards,
Allan Dystrup