?
Solved

simple regexp...

Posted on 2000-05-09
3
Medium Priority
?
228 Views
Last Modified: 2010-03-05
How can I get the 5th and 6th letters from an 8 letter code and assign them to a scalar variable?

For example, if the code is ABCDEFGH I'd like the scaler to have the value of EF.
thanks,
0
Comment
Question by:frenomulax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
jyu_88 earned 200 total points
ID: 2795373
you don't need a reg. substr function will take care of it.

my $code="ABCDEFGH";
my $fifthAndSixth = substr($code, 4, 2);

substr(string, index of char to start, how many char in total including the starting char);

index of char in a string starts with 0, thus the '4' is the above snippet for the fifth char in the string. 'man perlfunc' for more details.

If you insist to use reg, you can use something like,

my $code="ABCDEFGH";
my $fifthAndSixth;
if ($code =~ /^\w{4}(\w{2})\w{2}$/) {
     $fifthAndSixth = $1
}
else {
     print "invalid code: <$code>\n";
}
0
 

Author Comment

by:frenomulax
ID: 2795426
Just what I need. Thanks!
0
 

Author Comment

by:frenomulax
ID: 2795427
Just what I need. Thanks!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Six Sigma Control Plans
Suggested Courses

770 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