regex - How to handle below pattern matching in Perl -
how below mentioned pattern match?
below input in array:
@array=("gs : asti:34:234", "gs : asti:344:543:wet");
i used foreach loop
split them , i'm pushing them array.
help me in resolving below issue.
foreach(@array) { if($_ =~ /gs/ig) { @arr2 = split(":",$_); #splitting matched pattern push(@y,$arr2[1]); } }
acutal output is: asti , asti
desired/expected output : asti:34:234 , asti:344:543:wet
you can in way, split strings in 2 parts:
use strict; use warnings; @array=('gs : asti:34:234', 'gs : asti:344:543:wet'); foreach(@array) { if($_ =~ m/gs/ig) { @arr2 = split(":", $_, 2); $arr2[1] =~ s/^\s+//; #to remove white-space push(my @y,$arr2[1]); print "@y\n"; } }
output:
asti:34:234 asti:344:543:wet
Comments
Post a Comment