+ 1
Transformation
If a symbol is 'A' and next is 'B', transform two symbols in 'C' Input: ABHJKAB Output: CHJKC
4 odpowiedzi
+ 6
#include <iostream>
#include <string>
#include <regex>
std::string new_str(std::string o)
{
return std::regex_replace(o, std::regex("AB"), "C");
}
int main()
{
std::cout << new_str("ABHJKAB");
return 0;
}
+ 1
@Hatsy Rei, can I do two replacements using regex_replace? For example I need to transform not only "AB" but and "BA" too
+ 1
and if I have "ABABA"
I must get "CCA"
+ 1
oh I got