Next | Regular Expression Mastery | 64 |
/^(\w+|::)*$/
Try
perl -Mre=debug -e '"abcd!" =~ /^(?:\w+|::)*$/'
It generates 279 lines of diagnostic output about the backtracking that it tried before it gave up.
perl -Mre=debug -e '"abcde!" =~ /^(?:\w+|::)*$/'
takes twice as long and generates twice as much: 535 lines. We would expect
perl -Mre=debug -e '"what_an_incredible_disaster!" =~ /^(?:\w+|::)*$/'
to take about 8,388,608 times as long and to generate 2,147,483,671 lines of output.
It doesn't take forever, but it's hard to tell the difference.
Next | Copyright © 2002 M. J. Dominus |