I would like to find $number
substrings and then replace them with $number + 1
format.
For example, $1
should become $2
in a string.
So far, I found out how to find $number
pattern in a string and then replace them with other string using regex and it works fine.
My Code :
#include <iostream>
#include <string>
#include <regex>
std::string replaceDollarNumber(std::string str, std::string replace)
{
std::regex long_word_regex("(\\$[0-9]+)");
std::string new_s = std::regex_replace(str, long_word_regex, replace);
return new_s;
}
int main()
{
std::string str = "!$@#$34$1%^&$5*$1$!%$91$12@$3";
auto new_s = replaceDollarNumber(str, "<>");
std::cout << "Result : " << new_s << '\n';
}
The Result :
Result : !$@#<><>%^&<>*<>$!%<><>@<>
The Result I want :
Result : !$@#$35$2%^&$6*$2$!%$92$13@$4
Is it possible to do this using regex?