I am using G++-5 with the dialect option -std=c++0x
and the preprocessor symbol __GXX_EXPERIMENTAL_CXX0X__
and I am trying to use the tr1/regex
.
I use #include <tr1/regex>
with using namespace std::tr1;
and regex reg("<[^>]*>");
trows no error.
Only when I use regex_replace(line, reg, "");
afterwards, I get the following error output:
Function 'regex_replace' could not be resolved test.cpp /cppUni/src line 72 Semantic Error
Invalid arguments '
Candidates are:
#0 regex_replace(#0, #1, #1, const std::tr1::basic_regex<#3,#2> &, const ? &, std::bitset<unsigned long int11>)
? regex_replace(const ? &, const std::tr1::basic_regex<#1,#0> &, const ? &, std::bitset<unsigned long int11>)
' test.cpp /cppUni/src line 72 Semantic Error
I verified, that line
is a String.
I searched for a solution the last couple of hours and could only find solutions that involved what I attempted.
Unfortunately I can't use the boost/regex
package.
Is there a solution for this issue?
EDIT:
#include <tr1/regex>
#include <iostream>
#include <string>
using namespace std;
int main(){
std::tr1::regex reg("<[^>]*>");
string line = "<Day>22</Day>";
if(line.find("<Day>") != string::npos)
{
line =std::tr1::regex_replace(line, reg, "");
cout<<line<<endl;
}
return 0;
}
g++-5 -std=c++11 -D__GXX_EXPERIMENTAL_CXX0X__ -Wall test.cpp -o test.out
To have this answered: User "Baum mit Augen" solved the issue by saying:
Alright, in tr1::regex you apparently need std::tr1::regex_replace(line, reg, string(""));. (Though that resulted in a linker error in Wandbox, but maybe they just don't have that legacy stuff installed, I dunno.) You should just use std::regex from C++11 instead, it works fine as I showed above. – Baum mit Augen May 28 at 11:10