in reply to the case where regex seems to work slower
Just fudge things a little :)
#!/usr/bin/perl # http://perlmonks.org/?node_id=1196089 use strict; use warnings; $\ = $/; my $dict = 'b'; $_ = '*' . 'a' x (9e4 - 1e4) . "\n"; my($head, $tail) = map length( $_ // '' ), split /\*/, $_; s/\?/[$dict]/g; s/\*/ [^$dict ]* /; my $qr = qr/^$_$/; substr($_, $head, 0, ' '), substr($_, -$tail, 0, ' '), print $_ =~ $qr ? "YES" : "NO" for 'a' x (0 + 1e4) . 'a' x (9e4 - 1e4) . "\n";
This avoids the massive backtrack this particular problem encounters.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: the case where regex seems to work slower
by rsFalse (Chaplain) on Jul 27, 2017 at 10:53 UTC | |
by tybalt89 (Monsignor) on Jul 27, 2017 at 11:40 UTC | |
by rsFalse (Chaplain) on Jul 27, 2017 at 12:57 UTC | |
by tybalt89 (Monsignor) on Jul 27, 2017 at 13:37 UTC |