fork download
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. # ^([\d]+(?:\.\d)?) # Match one or more digits
  7. # # followed by an optional period and digit
  8. # \s # followed by a whitespace character
  9. #
  10. # (years|months|days|hours|minutes)
  11. # # followed by a unit-of-time word
  12.  
  13. my @buf;
  14. while (<DATA>) {
  15. @buf = /^([\d]+(?:\.\d)?)\s(years|months|days|hours|minutes)/;
  16. print "[", join("][", @buf), "]\n";
  17. }
  18.  
  19. __DATA__
  20. 12 days ago
  21. 1 minutes ago
  22. 5.8 hours ago
  23. 3.2 years ago
  24.  
Success #stdin #stdout 0s 3740KB
stdin
Standard input is empty
stdout
[12][days]
[1][minutes]
[5.8][hours]
[3.2][years]