?
Solved

split

Posted on 2000-04-03
5
Medium Priority
?
160 Views
Last Modified: 2010-03-05
How to split the following:

"Quantity_381_04032000101718.x"

to

$a = "381";
and
$b = "04032000101718";

on a nice way???

or split it to:

$a = "381_04032000101718";
0
Comment
Question by:mmcw
[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
  • 2
5 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2681122
try this

#!/usr/local/bin/perl
$var="Quantity_381_04032000101718.x";

($junk,$a,$b)=split(/_/,$var);
$b=~ s/\..*//g;

print $a," => ",$b,"\n";
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 2681195
or

($a, $b) = /(\d+)_(\d+)/;

and for the second example:

($a) = /_([\d_]+)/;
0
 

Author Comment

by:mmcw
ID: 2681212
clockwatcher:

Your second answer does not work!!!
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 200 total points
ID: 2681227
$_ = "Quantity_381_04032000101718.x";
($a, $b) = /(\d+)_(\d+)/;
print "$a\n$b\n";

($a) = /_([\d_]+)/;
print "$a\n";

--------------------
Output:
381
04032000101718
381_04032000101718

Which is what you said you wanted.

>> or split it to:
>>  $a = "381_04032000101718";



0
 

Author Comment

by:mmcw
ID: 2681250
Thank you.
I made a mistype
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!

Question has a verified solution.

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

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.…
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

649 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