hello this is my c++ regex
regex MyRGX(R"~((\w*)\s*[(]([^;]*)[)]\s*[;])~");
and this is my string
Data1 (
anything1
);
this regex get Data1
and everything exists between ();
with any condition. but when i have more than 50 blocks like Data1
, this regex search speed is going to be lower than equivalent regex in pcre. i think this regex that i have, isn't optimize for speed. do you have any suggestion to increase speed of this regex with this conditions (get everything exists between ();
and ...) ?
As I suspected from your previous question, this looks like a case where Regex isn't the most logical solution.
"Regex" comes from "Regular Expressions" which describe "Regular Languages". And languages with matched parentheses (like C++ itself) are not regular. Now, what we call "regex" has evolved to include some non-regular languages, but that's not optimal.
In this case, it looks like a perfectly ordinary parser would work. As I understand it, the goal is to look for anything between (
and );
. So do a simple text search forward for (
, backwards for );
. Check that both are found and that (
precedes );
, then just use the index pair found to extract the substring.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.