Shouldn't be any more complex than:
string source = @"
batman: 100
robin: OFXSGML
superman: 102
wonderwoman: NONE
joker: USASCII
harley: 1252
aquaman: NONE
flash: NONE
iris: NONE
".Trim();
Regex rx = new Regex(@"(?<=:)\s+");
string result = rx.Replace(source, "");
(?<=:) is a zero-width positive lookbehind: it anchors the match on a :, without it being a part of the match.
\s+ matches 1 or more whitespace characters (SP, HT, CR, LF, VT).
That changes:
batman: 100
robin: OFXSGML
superman: 102
wonderwoman: NONE
joker: USASCII
harley: 1252
aquaman: NONE
flash: NONE
iris: NONE
into
batman:100
robin:OFXSGML
superman:102
wonderwoman:NONE
joker:USASCII
harley:1252
aquaman:NONE
flash:NONE
iris:NONE
Alternatively, you can include the : in the match. It just changes the replacement text:
Regex rx = new Regex(@":\s+");
string result = rx.Replace(source, ":");
If you care about the value of the key preceding the colon-plus-whitespace, use named capture groups and a match evaluator.
Here the regular expression (?<key>\w+)\s*:\s* matches:
(?<key>\w+) — a sequence of 1 or more whitespace characters (letters, digits or _), followed by
\s* — zero or more whitespace characters, followed by
: — a literal colon character, followed by
\s* — zero or more whitespace characters
The match evaluator looks at the capturing group named key. If it is any of batman, robin, or superman, any whitespace preceding or following the colon is removed; otherwise, the match itself is returned unchanged.
Regex rx = new Regex(@"(?<key>\w+)\s*:\s*");
string result = rx.Replace(source, (Match m) => {
string replacement;
string key = m.Groups["key"].Value;
switch (key) {
case "batman":
case "robin":
case "superman":
replacement = key+":";
break;
default:
replacement = m.Value;
break;
}
return replacement;
});