Solved

split

Posted on 2000-04-03
5
152 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
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:maneshr
Comment Utility
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
Comment Utility
or

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

and for the second example:

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

Author Comment

by:mmcw
Comment Utility
clockwatcher:

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

Accepted Solution

by:
clockwatcher earned 50 total points
Comment Utility
$_ = "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
Comment Utility
Thank you.
I made a mistype
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now