Help for this page

Select Code to Download


  1. or download this
    my $s = "123 45 6 789";
    while ($s =~ m/\d+/g) {
      print "> $&\n";
    }
    
  2. or download this
    > 123
    > 45
    > 6
    > 789
    
  3. or download this
    my $s = "123  carrots   45 6  bananas 789";
    while (1) {
    ...
      $s =~ /\G([a-z]+)/gc and print "WORD $1\n" and next;
      $s =~ /\G$/gc and last;
    }
    
  4. or download this
    NUMBER 123
    SPACE
    ...
    WORD bananas
    SPACE
    NUMBER 789
    
  5. or download this
    NUMBER 123
    NUMBER 45
    NUMBER 6
    NUMBER 789
    
  6. or download this
    my $s = "123  carrots   45 6  bananas 789";
    while ($s =~ /(\d+)/g) {
      print "'$1' at position ", pos($s)-length($1), "\n";
    }
    
  7. or download this
    '123' at position 0
    '45' at position 15
    '6' at position 18
    '789' at position 29
    
  8. or download this
    my $s = "123  carrots   45 6  bananas 789";
    while ($s =~ /(\d+)/g) {
      print "'$1' at position ", pos($s)-length($1), "\n";
      pos($s) += 13;
    }
    
  9. or download this
    '123' at position 0
    '5' at position 16
    '89' at position 30