Swap the first two words in a string : translation « Regular Expression « Perl






Swap the first two words in a string

    
#!/usr/bin/perl
use warnings;
use strict;
$_ = "Berkeley: LSD and UNIX";

s/(\w+)\s+(\w+)/$2 $1/;
print $_, "?\n";

   
    
    
    
  








Related examples in the same category

1.Options for the translation operator.
2.Introducing the translation operator
3.Occurences of planet were changed to world