in reply to OCR matching regex
#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1178025 use strict; use warnings; while(<DATA>) { my ($want, $in) = split; my $pat = $want =~ s/\B/?.?/gr . '?'; #print $pat; my (@answers, %found); $in =~ /$pat(?{$found{$&}++ or $answers[length $&] .= "$& "})(*FAIL) +/; print "$want in $in is ", @answers ? $answers[-1] : 'not found'; } __DATA__ ABC DFGABCKBG ABC DFGAXBHCY ABC DFGAXBHY
Many more test cases are needed :)
Also an explanation of why ABC DFGAXBHY should be AXB instead of AXBH
Also what should be done if there is more than one "longest".
Also, can there be more than one extra character between wanted chars, and if so, how many?
|
|---|