Solved

split

Posted on 2000-04-03
5
158 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 50 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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

696 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