home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / perl / 7781 < prev    next >
Encoding:
Text File  |  1993-01-12  |  1.6 KB  |  38 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!spool.mu.edu!howland.reston.ans.net!sol.ctr.columbia.edu!eff!ckd
  3. From: ckd@eff.org (Christopher Davis)
  4. Subject: Re: pattern matching
  5. In-Reply-To: hans@symbas.UUCP's message of 12 Jan 93 17:48:59 GMT
  6. Message-ID: <CKD.93Jan12162531@loiosh.eff.org>
  7. Sender: usenet@eff.org (NNTP News Poster)
  8. Nntp-Posting-Host: loiosh.eff.org
  9. Organization: Electronic Frontier Foundation Tech Central
  10. References: <3730@symbas.UUCP>
  11. Date: Tue, 12 Jan 1993 21:25:33 GMT
  12. Lines: 24
  13.  
  14. HA> == Hans Aafloy <hans@symbas.UUCP>
  15.  
  16.  HA> I expexted the constructs /\d{1,1}/ or /\d{1}/ to match single digits
  17.  HA> only, but it seems to match multiple digit numbers as well.
  18.  
  19. No, it's only *matching* the first one; the catch is that you haven't
  20. anchored the search in such a way as to prevent it from matching a single
  21. digit followed by another digit :)
  22.  
  23.  HA> My problem is trivial, and I know a couple of ways to get around
  24.  HA> it, but since I'll use Perl a lot in the future, I want to get to
  25.  HA> the bottom of things like this.
  26.  
  27.  HA> I simply want to insert a leading zero in front of a one digit date:
  28.  HA> s/ *(\d{1})/0$1/;
  29.  HA> and it replaces 88 with 088 as well as 8 with 08.
  30.  
  31. Try s/(\D)(\d\D)/$10$2/; though this doesn't have provision for the
  32. beginning or end of a line (those are left as an exercise for the reader).
  33. --
  34. Christopher K. Davis      | ``Usenet seems to run much like the Kif (or,
  35. <ckd@eff.org>   EFF #14   |   for the TV generation, Klingon) high command.
  36. System Administrator, EFF |   Whoever takes action and can be heard wins.''
  37. +1 617 864 0665  [CKD1]   |   --Peter da Silva <peter@ferranti.com>
  38.