Re: Pattern Matching Question



Ruud wrote:

> #!/usr/bin/perl
> use strict; use warnings;

> my $HugeString = 'xxxxAaAaAaAaAaSDFGHJKLxxxx';
> my $Head = 'AAAAAAAA';

> print "$1$2$3\n"
> while $HugeString =~ /(?<=($Head))(.)(?=(.{7}))/ig;


Your method does not comply with the author's stated parameters.
This regex method you present works as written, but does not match
the correct string per original parameters. Nice method but it does
produce incorrect results.

For reader trivia, some benchmark results comparing a substring method
to the regex method presented by Ruud, although not correct per the
author's stated parameters.

Benchmark: timing 100000 iterations of PurlGurl, Ruud...
PurlGurl: -1 wallclock secs ( 0.60 usr + 0.00 sys = 0.60 CPU) @ 166666.67/s
Ruud: 8 wallclock secs ( 7.36 usr + 0.00 sys = 7.36 CPU) @ 13586.96/s
.