How can I store captures from a Perl regular expression into separate variables?

后端 未结 5 975
无人及你
无人及你 2020-12-15 06:01

I have a regex:

/abc(def)ghi(jkl)mno(pqr)/igs

How would I capture the results of each parentheses into 3 different variables, one for each

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 06:44

    Your question is a bit ambiguous to me, but I think you want to do something like this:

    my (@first, @second, @third);
    while( my ($first, $second, $third) = $string =~ /abc(def)ghi(jkl)mno(pqr)/igs) {
        push @first, $first;
        push @second, $second;
        push @third, $third;
    }
    

提交回复
热议问题