reg expr, extract digit from string.

J

joel

Hi,

I need help with extracting digit from a string.

example:

here is the string i want to split into words and digits.

my $string = "abcd-efgh-ijkl-123.456.789"

i want

$word = "abcd-efgh-ijkl";

and

$digit = "123.456.789";



Thanks in advance,

Joel
 
A

Arndt Jonasson

I need help with extracting digit from a string.

example:

here is the string i want to split into words and digits.

my $string = "abcd-efgh-ijkl-123.456.789"

i want

$word = "abcd-efgh-ijkl";

and

$digit = "123.456.789";

You seem to have split it successfully yourself already. What's the
general pattern for your string and word/digit parts? Does the
digit part contain only digits and periods, and the word part only
letters and hyphens?
 
J

John W. Krahn

joel said:
I need help with extracting digit from a string.

example:

here is the string i want to split into words and digits.

my $string = "abcd-efgh-ijkl-123.456.789"

i want

$word = "abcd-efgh-ijkl";

and

$digit = "123.456.789";

$ perl -le'
my $string = "abcd-efgh-ijkl-123.456.789";
my ( $word, $digit ) = split /(?<=\D)-(?=\d)/, $string, 2;
print for $word, $digit;
'
abcd-efgh-ijkl
123.456.789



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top