Skip site navigation (1) Skip section navigation (2)

Re: Regular Expression Help?

From: David Fetter <david(at)fetter(dot)org>
To: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: Regular Expression Help?
Date: 2003-11-05 15:22:35
Message-ID: 20031105152235.GU14711@fetter.org (view raw or flat)
Thread:
Lists: sfpug
On Tue, Nov 04, 2003 at 08:56:29PM -0800, David Wheeler wrote:
> On Tuesday, November 4, 2003, at 08:50  PM, David Fetter wrote:
> 
> >>>$eline =~ s/(#\w+)/$replacements{$1} || $1/ge;
> >
> >I'd be a little scared to use this one because #\w+ matches more
> >things than I know about for sure.
> 
> Yes, but I've allowed for that by just using $1 if it doesn't exist
> in %replacements.

D'oh!  I missed that.

> >It might be a little less maintenance to do something like
> >
> >$match = qr{ "(". join("|", keys %replacements) . ")" }o;
> >
> >$eline =~ s/$match/$replacements{$1}/g;
> 
> Yeah, that's cool, too, although the terminal "o" probably isn't
> needed, because a qr// is defined once by default!

That makes sense--after all, why would it compile more than once?

Cheers,
D
-- 
David Fetter david(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100    cell: +1 415 235 3778

In response to

Responses

sfpug by date

Next:From: Josh BerkusDate: 2003-11-05 17:48:33
Subject: Re: Regular Expression Help?
Previous:From: David WheelerDate: 2003-11-05 04:56:29
Subject: Re: Regular Expression Help?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group