Hello,when compile code i have problem
compiler say's ... srd::regex_error aborted(core dumped)
any idea why?????????
Also regex_replace dont recognize ...
// regex_replace example
#include <iostream>
#include <string>
#include <regex>
#include <iterator>
int main ()
{
std::string s ("there is a subsequence in the string\n");
std::regex e ("\\b(sub)([^ ]*)"); // matches words beginning by "sub"
// using string/c-string (3) version:
std::cout << std::regex_replace (s,e,"sub-$2");
// using range/c-string (6) version:
std::string result;
std::regex_replace (std::back_inserter(result), s.begin(), s.end(), e, "$2");
std::cout << result;
// with flags:
std::cout << std::regex_replace (s,e,"$1 and $2",std::regex_constants::format_no_copy);
std::cout << std::endl;
return 0;
}
The GNU implementation did not have <regex> support before version 4.9.
For reasons that I have never been able to appreciate, their earlier versions compiled code using <regex> without so much as a murmur, and then their library threw regex_error (for well-formed constructs) at the unsuspecting programmer.
Ok, updating to gcc 4.9 all are ok. C::B works fine.
But my problem continues. In code i take for 11,75 the a1175 and all are ok.
1 2 3 4 5 6
std::wstring str = L"We bought the grocer oil worth 2,48 drachmas. ""soap worth 94 drs. and rice worth 11,75 drachmas.""How much change will take from 7/8 of 50 drachmas?";
std::wregex num(L"\\b([0-9]*),([0-9]*)");
std::wcout<<std::regex_replace(str,num,L"a$1$2")<<"\n";
But trying get all mutching strings sm size is 0. But why sm gives 0, after the result in replace is correct?
Ah, you're using regex_match() when you should be using regex_search().
regex_match() attempts to match the entire expression...
which it will fail to do in your case, because you are trying to find a sub-expression that matches your string. Use regex_search() to find sub-expressions.
Thank you very mutch.
A last question... I am trying to catch only integers.
From 2,48 94 11,75 7/8 50 and 35 6/9, i must catch only 94 and 50.
Trying \\b([0-9]+) or \\b([0-9]*) etc... i have problem.
Any idea for regular expression?