Hello Jim - a well-placed query is often as powerful as providing a complete answer, so thanks for your perspicacious line of questioning. The following works but I'm using two regex objects, the second to remove the additional whitespace. Is there any way they can be combined into one?
Code:
# include <iostream>
# include <fstream>
# include <string>
# include <regex>
int main()
{
std::ifstream inFile{"F:\\test.txt"};
std::regex re{"\\b[0-9]+ | \\b[0-9]+(.)[0-9]+"};
// numbers without decimals - regex separator - numbers with decimals
std::regex re1{"[\\s]{2}"};
// preceding atom has exactly two consecutive whitespaces
if (inFile)
{
std::string line{};
while (getline(inFile, line))
{
line = std::regex_replace(line, re, "");
line = std::regex_replace(line, re1, " ");
std::cout << line;
}
}
}
Sample File (now contains a number without decimals as well for testing the regex)
The National Bureau 45 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.