I have a huge paragraph of text stored in std :: string called 'text'. In this line, I replace certain patterns with a space using the regex boost library. Here is my code.
// Remove times of the form (00:33) and (1:33) boost::regex rgx("\\([0-9.:]*\\)"); text = boost::regex_replace(text, rgx, " "); // Remove single word HTML tags rgx.set_expression("<[a-zA-Z/]*>"); text = boost::regex_replace(text, rgx, " "); // Remove comments like [pause], [laugh] rgx.set_expression("\\[[a-zA-Z]* *[a-zA-Z]*\\]"); text = boost::regex_replace(text, rgx, " "); // Remove comments of the form <...> rgx.set_expression("<.+?>"); text = boost::regex_replace(text, rgx, " "); // Remove comments of the form {...} rgx.set_expression("\\{.+?\\}"); text = boost::regex_replace(text, rgx, " "); // Remove comments of the form [...] rgx.set_expression("\\[.+?\\]"); text = boost::regex_replace(text, rgx, " ");
From my point of view, every time I run the regex_replace function, it creates a new line and writes the output to it. If I run the regex_replace function with N different templates, it will highlight N new lines (deleting the old ones).
Since memory allocation is time consuming, is there a way to do an in-place replacement without highlighting a new line?
source share