This thread may be dead, but I'll add my comment anyway.
Assume the problem is to recognize that two strings, s1 and s2, are associated when the strings are exactly the same except that a '$' character has been: inserted exactly once anywhere (including at the ends) in s2, or substituted exactly once for any character in s2.
Then a solution might make use of the idea of Levenshtein Distance (LD), which, as I understand it (and you would do well to double-check my understanding), is the number of characters that need to be inserted, changed or deleted in a string in order to transform it into another string.
So if s1 has no '$' character in it, and s2 has at least one '$', and the LD between s1 and s2 is exactly one, then s2 is exactly like s1 except that exactly one '$' has been inserted or substituted into s2.
Note, however, that 'test.ext' matches with 'test$ext'.
I am using the expression $try =~ m{ \$ }xms in the function acquired_1_dollar() because the OPer asked for something using a regex. This might more straightforwardly be index($try, '$') >= 0. I can't think of any (fairly simple) way to do the entire match using only a regex.
Also, I use Text::LevenshteinXS only because I could not get Text::Levenshtein, both from the ActiveState repository, to work.
C:\@Work\Perl\monks\dani_cv>perl -wMstrict -le
"use Text::LevenshteinXS qw(distance);
my $base = shift;
print qq(\noutput:);
for my $try (@ARGV) {
my $no = acquired_1_dollar($base, $try) ? q{} : q{NO };
print qq{$base <> $try: ${no}match};
}
sub acquired_1_dollar {
my ($base, $try) = @_;
return $try =~ m{ \$ }xms && distance($base, $try) == 1;
}
"
test.ext
$test.ext te$st.ext test$.ext test.$ext test.e$xt test.ext$
$est.ext te$t.ext tes$.ext test$ext test.$xt test.e$t test.ex$
test.ext tost.ext te$t$.ext tet.ext t$t.ext tes$t$xt test$e$t
"" $ test wertyu wert$yu w$er$tyu
output:
test.ext <> $test.ext: match
test.ext <> te$st.ext: match
test.ext <> test$.ext: match
test.ext <> test.$ext: match
test.ext <> test.e$xt: match
test.ext <> test.ext$: match
test.ext <> $est.ext: match
test.ext <> te$t.ext: match
test.ext <> tes$.ext: match
test.ext <> test$ext: match
test.ext <> test.$xt: match
test.ext <> test.e$t: match
test.ext <> test.ex$: match
test.ext <> test.ext: NO match
test.ext <> tost.ext: NO match
test.ext <> te$t$.ext: NO match
test.ext <> tet.ext: NO match
test.ext <> t$t.ext: NO match
test.ext <> tes$t$xt: NO match
test.ext <> test$e$t: NO match
test.ext <> : NO match
test.ext <> $: NO match
test.ext <> test: NO match
test.ext <> wertyu: NO match
test.ext <> wert$yu: NO match
test.ext <> w$er$tyu: NO match
|