Regex_replace numbers in .txt file
I want to regex_replace all numbers in a .txt file but for numbers with decimals the period separator remains:
Code:
# include <iostream>
# include <fstream>
# include <string>
# include <regex>
int main()
{
std::ifstream inFile{"F:\\test.txt"};
std::regex re{"\\b[0-9]+"};
if (inFile)
{
std::string line{};
while (getline(inFile, line))
{
line = std::regex_replace(line, re, "");
std::cout << line;
}
}
}
Sample File
The National Bureau of Statistic's official Purchasing Managers' Index (PMI) came in at 51.2 higher than the 51.0 expected and even with 51.2 in April, Reuters reported. China's steel PMI rose to 54.8 in May from 49.1 in April. Meanwhile, China's official services PMI rose to 54.5 in May from 54.0 in April.
ps: there might be other ways of accomplishing this task but I'd like to use regex in this instance. Thanks