Just another Perl shrine | |
PerlMonks |
Re: Extract last two digits from numbersby yosefm (Friar) |
on Jan 06, 2004 at 10:13 UTC ( [id://319064]=note: print w/replies, xml ) | Need Help?? |
Assuming the number is at the end of the variable being matched, use: /\d{2}$/. the '\d' means match digits, the '{2}' means two exactly, and the '$' means end of line. Other option: /\d\d$/ (simpler).
Update: Note that L~R's regex is more specific (putting '^' first means start of line) while tachyon's regex is more relaxed, finding any 4 digit number and capturing its last two digits (using parentheses). Another update: See L~R's reply below.
In Section
Seekers of Perl Wisdom
|
|