"But this time, when I try to pull out 81 from the string A81, it doesn't do what I expected (Regex Coach shows that it's matching both numbers):

You're getting a match using (\d)+ but it's not a precise match. This is why others have said to change (\d)+ to (\d+). Also keep in mind that if you know your data will ALWAYS be formatted Letter_DIGIT_DIGIT as in A81 with no other characters after, (\d+) or even (\d{2}) (matches only if two digits exist) will work.

However if you have something like 'A81342545342' the precision of those regexes will be watered down significantly matching every digit after 'A' with (\d+) '81342545342', to loosely matching every pair after 'A' with something like (\d{2}) '81 34 25 45 34'. This is why knowing the context of the data you're searching within is very important (as has been mentioned). Regular Expressions will give you varying levels of precision. It's up to you to weigh how precise you need to be and proceed accordingly.


"...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote

In reply to Re: assigning regex matches to variables by luis.roca
in thread assigning regex matches to variables by genghis

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.