Thanks to all for the help.  As j proctor noticed, the problem isn't
matching $asdf =~ /HK\$/ it's matching \$ without HK, and any other
currency symbol that includes \$.

Instead of trying to understand "zero-width negative lookbehind assertions"
(shown below), I just took the easy way out of trying to match all the
symbols except \$, then if there were no matches, assuming it to be \$.

Thanks again, and of course try out the world's best currency converter at
www.joelman.com/currency

At 02:21 PM 1/9/01 -0500, j proctor wrote:
>
>> OK.  I suck at regex's.  Here's the thing.  For my currency converter, I've
>> got a bunch of currency symbols, like $, DM, HK$, etc.  Let's say I want to
>> match a price in Hong Kong dollars.  The symbol is HK$ and I want to match
>> HK$, not $.  What's the regex to do this?
>
>That's easy.  /HK\$/ will work just fine (provided you don't forget the
>backslash before the $).  
>
>It's matching $ without an HK in front that's tricky.
>
>The easy way:  test for HK$ (and every other ...$) first; if it falls
>through all of those and still has a $ in it, you can possibly assume
>it's US$ (depending on the data source, of course).
>
>If that's not an option, Perl 5 added zero-width negative lookbehind
>assertions: /(?<!HK)\$/ will match any $ that's not preceeded by HK.  If
>you have other dollar-like currencies, presumably something like
>/(?<!(HK|CDN|whatever))\$/ will work.
>
>
>j

---------------------------------------------------------------------
Joel Gwynn                              Designers' CADD Company, Inc.
A bus station is where a bus stops. 
A train station is where a train stops. 
So now you know why they call this a workstation... 

Reply via email to