#include <iostream>
#include <regex>

int main() {
	std::string s{ "A;1;\nB;2\nC;3" };
	const std::regex re("([^;]|^)(\\n)");  // Produces "A;1;;\nB;2;\nC;3" (redundant ";" after "1").
	s = std::regex_replace(s, re, "$1;$2");
	std::cout << s;
	return 0;
}