Perl - How to find the string after a specific delimiter

ambuli
ambuli used Ask the Experts™
on
Hi there,

I want to find the following

nameOne: string1 Value: 1234, 2345, 2454

I want to extract this so that
I can get the values for nameOne, Value, and the other two numbers in the end.  nameOne, and Value are followed by ":", but the ending numbers are separated by ",".
Value will be a numeric number too.


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
$string =~ m{nameOne:\s*(.*?)\s+Value:\s*(\d+),\s*(\d+),\s*(\d+)\s*$};
my ($name1, $val, $num1, $num2) = ($1, $2, $3, $4);
Try something like:
 
#!/bin/env perl

use strict;
use warnings;

my $str = "nameOne: string1 12345: 1234, 2345, 2454";
$str =~ m/(\w+):.*? (\d+):\s+(\d+), (\d+), (\d+)/;
my $NameOne = $1;
my $Value = $2;
my $num1 = $3;
my $num2 = $4;
my $num3 = $5;

Open in new window

Author

Commented:
Thank you.  One other question.  What changes should I make if the line is

some other a nameOne: string1 Value: 1234, 2345, 2454

Author

Commented:
sorry

some other: a nameOne: string1 Value: 1234, 2345, 2454,

Author

Commented:
Thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial