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

In reply to Re: file$name.class find - regexp ? by AnomalousMonk
in thread file$name.class find - regexp ? by dani_cv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.