in reply to search of a string in another string with 1 wildcard

So, don't search "abcdfg" [ :-) what happened to 'e' ? ]

But -- more seriously -- what do you mean by the statement that '"abcdfg", "fbcdfg", "aMcdfg", "abZdfg" etc are accepted' when only the first combination actually exists in your all-lower-case-string and the last two require upper case letters?

From the info in your question, there are several ways to solve your problem -- some quite easy (see the following list) -- but it's easier to avoid off-track suggestions if the question is unambiguous AND we've seen your code (for a hint at what you're actually trying to accomplish). And various combinations of the above.

See On asking for help -- the "short version' at the top of that node will illuminate your next question.

Updated: Multiple edits of typos and formatting. Only the second para is actually new. Mea culpa. Brain seized in the heat.


check Ln42!

  • Comment on Re: search of a string in another string with 1 wildcard

Replies are listed 'Best First'.
Re^2: search of a string in another string with 1 wildcard
by choroba (Cardinal) on Jul 29, 2014 at 09:30 UTC
    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;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ