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