jeudi 11 mai 2017

match multiple patterns and extract subpatterns into a array in perl

my $str = 'assign (rregbus_z_partially_resident | regbus_s_partially_resident | reg_two | )regbus_;' ;

I want to parse this line and only capture all the string that starts with non-word characterm followed by either reg_\w+ or regbus_|w+ into an array.

so in the above example, i want to capture only regbus_s_partially_resident and reg_two into a array.

I tried this and it didnot work: my (@all_matches) = ($str =~ m/\W(reg_\w+)|\W(regbus_\w+)/g);

Since i am trying to use \W, its copying the non-word character also into the array list, which i donot want.

Aucun commentaire:

Enregistrer un commentaire