[forwarded submission from a non-member address -- rjk]


From: [EMAIL PROTECTED]
Date: Tue, 9 Jan 2001 14:34:50 -0500
Subject: Re: [Boston.pm] regex help
To: Joel Gwynn <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]

On Tue, Jan 09, 2001 at 12:58:52PM -0500, Joel Gwynn 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?

/HK\$/ # matches if the line has "HK$"

You probably want to capture the price as well

/HK\$\s*(\d+\.?\d*)/ # price in $1

This matches:

HK$ 100
HK$50
HK$ 62.4
HK$ 56.45

Also note that is captures the *leftmost* instance of the pattern
for a given line.

Hope this helps.


-- 
----------------
Joe Johnston  - http://aliensaliensaliens.com
"Only presidents, editors and people with tapeworms 
ought to have the right to use *we*." -Mark Twain

Reply via email to