Back referencing : Index « Regular Expression « Perl






Back referencing

    

while(<DATA>){
    ($first, $last)=/(\w+) (\w+)/;   # Could be: (\S+) (\S+)/
    print "$last, $first\n";
}
__DATA__
    First Last

   
    
    
    
  








Related examples in the same category

1.Backreferencing and greed
2.Backreferencing and greedy quantifiers
3.Match the first alphanumeric character
4.Matched index
5.$1 gets 'A', $2 gets' B'
6.Regex index