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

Re: Regular Expression Help?

From: David Wheeler <david(at)kineticode(dot)com>
To: David Fetter <david(at)fetter(dot)org>
Cc: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: Regular Expression Help?
Date: 2003-11-05 04:56:29
Message-ID: 6ACCE8FA-0F4C-11D8-B9C0-0003931A964A@kineticode.com (view raw or flat)
Thread:
Lists: sfpug
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.

> 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!

Cheers,

David

-- 
David Wheeler                                     AIM: dwTheory
david(at)kineticode(dot)com                              ICQ: 15726394
http://www.kineticode.com/                     Yahoo!: dew7e
                                                Jabber: Theory(at)jabber(dot)org
Kineticode. Setting knowledge in motion.[sm]


In response to

Responses

sfpug by date

Next:From: David FetterDate: 2003-11-05 15:22:35
Subject: Re: Regular Expression Help?
Previous:From: David FetterDate: 2003-11-05 04:50:16
Subject: Re: Regular Expression Help?

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