I have no problem using from_patterm/to_pattern to rewrite either X_Y_Z→X.Y.Z or X_Y→X.Y, but I have an upstream source with a variable number of segments in their underscore-formatted tag scheme that I need to translate to dot separators.
I can match on it of course and transform it to something, but I can't figure out how to only include the trailing .\\3 if and only if there is a third section to match.
I can almost get away with stuffing a zero in the third segment:
I have no problem using
from_patterm
/to_pattern
to rewrite either X_Y_Z→X.Y.Z or X_Y→X.Y, but I have an upstream source with a variable number of segments in their underscore-formatted tag scheme that I need to translate to dot separators.I can match on it of course and transform it to something, but I can't figure out how to only include the trailing
.\\3
if and only if there is a third section to match.I can almost get away with stuffing a zero in the third segment:
But that actually falls afoul of version sorting rules for other reasons.
Is there a way to do simple substitution (e.g. replace
_
→.
) or to add a string to a backreference only if it is not empty?