[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

simple regexp...

Posted on 2000-05-09
3
Medium Priority
?
236 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

656 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