Tam Nguyen
Tam Nguyen

Reputation: 1165

Can we redefine a regex?

I am using regex to format my input string, my problem is that my string has to replace too many different values so that I have to use many regexes.

My question is, can I redefine a regex to save the system memory?

std::regex y_re("y+");
y_re("a+"); // can I do this, it shows error but is there a way to reuse regex?

Upvotes: 0

Views: 155

Answers (1)

42yeah
42yeah

Reputation: 91

Try redefining in this way:

std::regex y_re("y+");
y_re = std::regex("a+");

The memory should be reused.

Upvotes: 1

Related Questions