fork(46) download
  1. #include <iostream>
  2. #include <regex>
  3. using namespace std;
  4.  
  5. int main() {
  6. std::string buffer = " li 12.12 si 43,23 45 31 uf 889 uf31 3.12345";
  7. std::regex rx(R"((?:^|\s)([+-]?[[:digit:]]+(?:\.[[:digit:]]+)?)(?=$|\s))");
  8. std::smatch m;
  9. std::string str = buffer;
  10. while (regex_search(str, m, rx)) {
  11. std::cout << "Number found: " << m[1] << std::endl;
  12. str = m.suffix().str();
  13. } // 12.12 45 31 889 3.12345
  14. return 0;
  15. }
Success #stdin #stdout 0s 3496KB
stdin
Standard input is empty
stdout
Number found: 12.12
Number found: 45
Number found: 31
Number found: 889
Number found: 3.12345