line 2 below ... it searches for a leter in lowercase.
Actually, it's any letter, upper OR lower, because of the /i modifier. Which makes this line 2 exactly equivalent to your 'this might work' line (let's call it line 4), so yes, line 4 works as well.

Is the letter $0 and the number $1 ? I assume so.
$0 returns the name of the program being run. $& returns the entire matched string. $1 and $2 return the first and second captured (patterns in parens) matches, so yes in lines 2, 3 and 4 the letter is $1 and the number is $2. Note the exception here is line 1, where the number is $1 -- this is because the look-behind (?<=foo) is zero-width and isn't considered part of the match.

I am curious how lines 2 and 3 below work.
Your description of line 2 (with the above case-correction) was accurate. The difference between line 2 and line 3 is that line 2 matches a single character from a character class (in this case only a letter) and that line 3 will match any character at all. For example, try them both against the strings "A1", "+1", "11", "A111" and compare the results.

In reply to Re^5: replace a digit with another digit by davidrw
in thread replace a digit with another digit by kevyt

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.