Okay, the part that is your 'landmark' is the '-'. So you put that in the RE to recognize, but not to 'capture'. You do want to capture the digits, so you use the '\d' (shorthand for [0-9]) to recognize the digits, and surround those with capturing parentheses. So the RE would look like "/-(\d\d)/". But then you want to _use_ it as you said, to get the value, so ...
my $thing = '1232-32';
my $value;
if( $thing =~ m/-(\d\d)/ ) {
$value = $1;
printf "I found '%s'\n", $value;
} else {
printf "I didn't find what I was expecting in '%s'\n", $thing;
}
But that would scare many of us because it doesn't check whether there might be more or less than two digits, or whether there are strange characters following the digits, and other such errors. So for the string you showed us,
we'd probably feel like saying something like
if( $thing =~ m/^\d+-(\d+)$/ ) {
but that might be too much checking for your purposes.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.