home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / perl / 7783 < prev    next >
Encoding:
Internet Message Format  |  1993-01-12  |  960 b 

  1. Path: sparky!uunet!portal!cup.portal.com!Eric-Amick
  2. From: Eric-Amick@cup.portal.com (Richard E Amick)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: pattern matching
  5. Message-ID: <73446@cup.portal.com>
  6. Date: Tue, 12 Jan 93 15:19:15 PST
  7. Organization: The Portal System (TM)
  8. References:  <3730@symbas.UUCP>
  9. Lines: 17
  10.  
  11. >I expexted the constructs    /\d{1,1}/  or /\d{1}/
  12. >to match single digits only, but it seems to match multiple digit
  13. >numbers as well.
  14. >My problem is trivial, and I know a couple of ways to get around
  15. >it, but since I'll use Perl a lot in the future, I want to get to
  16. >the bottom of things like this.
  17. >
  18. >I simply want to insert a leading zero in front of a one digit date:
  19. >s/ *(\d{1})/0$1/;
  20. >and it replaces 88 with 088 as well as 8 with 08.
  21.  
  22. The thing is that \d already matches a single digit!  Assuming that your
  23. one- or two-digit number is a separate word:
  24. s/\b(\d)\b/0$1/
  25. should do what you want.  The other possibility is using sprintf.
  26.  
  27. Eric
  28.