http://www.perlmonks.org?node_id=1095478


in reply to Re: search of a string in another string with 1 wildcard
in thread search of a string in another string with 1 wildcard

This seems similar to Multiple Approximate Pattern Matching Problem. Here's my solution:
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; chomp(my $text = <>); my @patterns = split ' ', <>; my $threshold = 0 + <>; my @ctext = split //, $text; my @results; for my $pattern (@patterns) { my @cpat = split //, $pattern; POSITION: for my $pos (0 .. @ctext - @cpat) { my $mismatches = 0; for my $i (0 .. @cpat - 1) { if ($cpat[$i] ne $ctext[$pos + $i]) { next POSITION if ++$mismatches > $threshold; } } push @results, $pos; } }; say join ' ', sort { $a <=> $b } @results;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ