perl regex grouping overload -



perl regex grouping overload -

i using next perl regex lines

$myalbum =~ s/[-_'&’]/ /g; $myalbum =~ s/[,’.]//g; $myalbum =~ m/([a-z0-9\$]+) +([a-z0-9\$]+) +([a-z0-9\$]+) +([a-z0-9\$]+) +([a-z0-9\$]+)/i;

to match next strings

"30_seconds_to_mars_-_30_seconds_to_mars" "30_seconds_to_mars_-_a_beautiful_lie" "311_-_311" "311_-_from_chaos" "311_-_grassroots" "311_-_sound_system"

what experiencing strings less 5 matching groups (ex. 311_-_311), attempting print $1 $2 $3 prints nil @ all. strings more 5 matches print.

how resolve this?

it looks want words in separate groups. me, seems you're abusing regexes when run substitutions , split. do:

$myalbum =~ s/[-_'&’]/ /g; $myalbum =~ s/[,’.]//g; @myalbum_list = split(/\s/, $myalbum); #print out whatever want/ test length, etc... print "$myalbum_list[0] $myalbum_list[1] $myalbum_list[2]";

regex perl

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -