I was really hoping to avoid constructing a regex beforehand because I have one and same regex object which I reuse by reassigning a new pattern each time it is used.
#include <regex>
#include <string>
int main()
{
std::regex regex;
std::string line;
regex = "something";
std::regex_search(line, regex);
regex = "something";
std::regex_search(line, regex);
regex = "something";
std::regex_search(line, regex);
// etc..
// However this time it must be case insensitive:
// how to make is case insensitive here without constructing a new one?
regex = std::regex("something", std::regex_constants::icase);
std::regex_search(line, regex);
}
This last case, is there a more efficient alternative to avoid a copy ctor?
Is it possible to make existing regex object case insensitive? ex. to manipulate it.
This last case, is there a more efficient alternative to avoid a copy ctor? Is it possible to make existing regex object case insensitive? ex. to manipulate it.
I don't think it's possible to adjust the syntax options of an existing regex.
The expensive part of constructing a typical regex is probably the process of compiling it into a finite automaton that can be interpreted, rather than any memory-to-memory copy or move construction/assignment.