Opened 13 years ago
Closed 13 years ago
#3513 closed Support Requests (invalid)
regex_match very slow example
Reported by: | Owned by: | Eric Niebler | |
---|---|---|---|
Milestone: | Boost 1.41.0 | Component: | xpressive |
Version: | Boost 1.40.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Hi,
I am having an issue with a dynamic regular expresion.
I have this source code.
sregex tempRE = sregex::compile("(?:.*
r?
n)*var wlanPara = new Array
(
r?
n
d{0,4},
r?
n\"(?P<ssid>(?:
w+))\",
r?
n(?P<channel>(?:
d{0,4})),
r?
n
d{0,4},
r?
n\"[
w-]+\",
r?
n\"[
w
.]+\",
r?
n
d{0,4},
r?
n
d{0,4},
r?
n\"(?P<signal>(?:
d{0,4})) dB\",
r?
n
d{0,4},
d{0,4}
);(?:.*
r?
n)*$");
std::string htmlText; filled using text in html file attached
smatch what;
if(regex_match(htmlText, what, tempRE)) {
...
}
When the program enters to the regex_match function, the process consumes 50% of the processor and the function never returns.
I was attach the html file that contains the text. The source code was tested using VisualStudio 2008.
If I use the static variant of regex, it's works perfectly..
sregex tempRE = bos >> *_ >> "var wlanPara = new Array(" >> _ln >> _d >> commonDigit >> ',' >> _ln >> '"' >> (s1= +_w) >> "\"," >> _ln >> (s2= commonDigit) >> ',' >> _ln >> commonDigit >> ',' >> _ln >> '"' >> +(_w | '-') >> "\"," >> _ln >> '"' >> +(_w | '.') >> "\"," >> _ln >> commonDigit >> ',' >> _ln >> commonDigit >> ',' >> _ln >> '"' >> (s3= commonDigit) >> " dB\"," >> _ln >> commonDigit >> ',' >> commonDigit >> " );" >> *_ >> eos;
Thanks,
Fernando Pelliccioni
Attachments (1)
Change History (2)
by , 13 years ago
comment:1 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Your dynamic regex is slow because you are needlessly using nested quantifiers in two places. The regex begins and ends with "(?:.*
r?
n)*". This case is explicitly called out in xpressive's docs as a common pitfall. Please read this:
Your static regex does not use nested quantifiers. That explains the difference.
HTML file that contains the text to parse