Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Help with perl regular expressions

I have a string that looks like this:

99-9999-A-9  format as dd-dddd-Alpha-d

I need to get three strings from this

First:  return first 6 numbers without hyphen    ex. 999999

Second: return alpha character   ex. A

Third: return last digit (no hyphen)   ex. 9
0
dmalovich
Asked:
dmalovich
  • 2
1 Solution
 
farzanjCommented:
my $var = '99-9999-A-9';
$var =~ /(\d\d)-(\d{4})-(\w)-(\d)/;
my $first = $1.$2;
my $second = $3;
my $third = $4;
0
 
farzanjCommented:
Another way:
my $var = '99-9999-A-9';
my ($first, $second, $third) = $var =~ /(\d\d-\d{4})-(\w)-(\d)/;
$first =~ s/-//;
print $first,"  ", $second, "  ", $third, "\n";
0
 
dmalovichAuthor Commented:
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now