Chunde  Huang
Chunde Huang

Reputation: 385

How to get the expression string of a Regex object in C++

I want to get the regular expression of the r object in foo, i.e: "A.B" Any idea?

//C++ 11 or higher,  Now I have an object of regex:
std::regex reg = std::regex("A.B");

//some other function with reg as input
void foo(regex r)
{
    string ab = ???;
}

Upvotes: 0

Views: 53

Answers (1)

UKMonkey
UKMonkey

Reputation: 6993

Reading http://www.cplusplus.com/reference/regex/basic_regex/ the answer is you can't; there is no function that provides that.

The solution, if you need that functionality, is to put it in a tuple/pair/custom struct and move them around together.

Upvotes: 1

Related Questions