in reply to assigning regex matches to variables
"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.
|
|---|