How can I extract the matches from the Perl match operator into variables?

前端 未结 6 1029
无人及你
无人及你 2020-12-29 08:09

If I have a match operator, how do I save the parts of the strings captured in the parentheses in variables instead of using $1, $2, and so on?

6条回答
  •  独厮守ぢ
    2020-12-29 08:29

    @strings goes on the left and will contain result, then goes your input string $input_string. Don't forget flag g for matching all substrings.

    my @strings=$input_string=~m/stuff (.*) stuff/g;
    

提交回复
热议问题