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