Solved

Help with perl regular expressions

Posted on 2012-03-28
3
291 Views
Last Modified: 2012-03-28
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
Comment
Question by:dmalovich
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 37778085
my $var = '99-9999-A-9';
$var =~ /(\d\d)-(\d{4})-(\w)-(\d)/;
my $first = $1.$2;
my $second = $3;
my $third = $4;
0
 
LVL 31

Expert Comment

by:farzanj
ID: 37778269
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
 

Author Closing Comment

by:dmalovich
ID: 37778319
Thanks
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl script not writing to .csv file 6 109
Union rows in array that have common elements 2 96
Extract data from span tag 1 92
Ned Perl Snippet to Read Files in Directory 5 69
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question