Reputation: 399
I need to extract multiple matches for a string on a single line. The line looks something like this:
./staticRoutes.10.10.30_VC;./staticRoutes.10.10.40_FEEDS
I need to extract each filename and put it in some @array. The file name on the line is separated by a ;. So in the above example, i want to extract just staticRoutes.10.10.30_VC and staticRoutes.10.10.40_FEEDS
Any help greatly appreciated.
Many thanks
John
Upvotes: 0
Views: 1244
Reputation: 92976
This would be the regex version, it would not contain the leading ./
in the result. If this is worth it, you can use this, otherwise I would prefer the split solution.
my $s = "./staticRoutes.10.10.30_VC;./staticRoutes.10.10.40_FEEDS";
my @res = $s =~ m~[^/]+(?=;|$)~g;
This would match any character that is not a /
(the [^/]+
part), before a ;
or the end of the string (the (?=;|$)
part)
Upvotes: 0
Reputation: 33908
my $some_string = './staticRoutes.10.10.30_VC;./staticRoutes.10.10.40_FEEDS';
my @array = split /;/, $some_string;
Upvotes: 2