$1 gets 'A', $2 gets' B' : Index « Regular Expression « Perl






$1 gets 'A', $2 gets' B'

    

$str = "A and B";
$str =~ s/(A) and (B)/$2, $1/i;  
print $str;

   
    
    
    
  








Related examples in the same category

1.Back referencing
2.Backreferencing and greed
3.Backreferencing and greedy quantifiers
4.Match the first alphanumeric character
5.Matched index
6.Regex index