Match regex and assign results in single line of code

后端 未结 9 2068
后悔当初
后悔当初 2021-02-02 06:45

I want to be able to do a regex match on a variable and assign the results to the variable itself. What is the best way to do it?

I want to essentially combine lines 2 a

9条回答
  •  萌比男神i
    2021-02-02 07:22

    You can do substitution as:

    $a = 'stackoverflow';
    $a =~ s/(\w+)overflow/$1/;
    

    $a is now "stack"

提交回复
热议问题