.NETGURU
Word boundaries
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngregexp' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Bob Levittan (VIP)
I'm trying to come up with a regex that matches a dollar amount, i.e.

$12.00 or $1.50 but not $1.234

\$[0-9]+(\.[0-9][0-9])?

works up to a point, but it matches more than 2 decimal digits. I want it to
fail if there are more than 2, so I figured that \b word boundary would
work.

\b\$[0-9]+(\.[0-9][0-9])?\b

but it doesn't. If I remove the \$ it works as I excpect, but the escaped
dollar seems to put it out of whack. Any suggestions?

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Reply to this message...
 
    
Kevin Collins
did you try it w/out the first \b ?

[Original message clipped]

Reply to this message...
 
    
Remas Wojciechowski
Bob,

how about you use a negative lookahead, i.e. find all matches that have
two digits after which there is not another digit:
[0-9][0-9](?![0-9])
[0-9][0-9] could be also written as [0-9]{2}

hth,
Remas
http://www.aspalliance.com/remas/

--- Bob Levittan <Click here to reveal e-mail address> wrote:
[Original message clipped]

=====
Remas Wojciechowski
http://www.aspalliance.com/remas/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

Reply to this message...
 
    
Bob Levittan (VIP)
But then $12.23XYZ would match, as X is not a digit.

----Original Message Follows----
From: Remas Wojciechowski <Click here to reveal e-mail address>
Reply-To: "aspngregexp" <Click here to reveal e-mail address>
To: "aspngregexp" <Click here to reveal e-mail address>
Subject: [aspngregexp] Re: Word boundaries
Date: Wed, 18 Jul 2001 08:36:25 -0700 (PDT)

Bob,

how about you use a negative lookahead, i.e. find all matches that have
two digits after which there is not another digit:
[0-9][0-9](?![0-9])
[0-9][0-9] could be also written as [0-9]{2}

hth,
Remas
http://www.aspalliance.com/remas/

--- Bob Levittan <Click here to reveal e-mail address> wrote:
[Original message clipped]

=====
Remas Wojciechowski
http://www.aspalliance.com/remas/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

| [aspngregexp] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Reply to this message...
 
    
Bob Levittan (VIP)
Actually:

^\$[0-9]+(\.[0-9][0-9])?$

does what I want - only matching a dollar amount, not matching within a
string.

----Original Message Follows----
From: Remas Wojciechowski <Click here to reveal e-mail address>
Reply-To: "aspngregexp" <Click here to reveal e-mail address>
To: "aspngregexp" <Click here to reveal e-mail address>
Subject: [aspngregexp] Re: Word boundaries
Date: Wed, 18 Jul 2001 08:36:25 -0700 (PDT)

Bob,

how about you use a negative lookahead, i.e. find all matches that have
two digits after which there is not another digit:
[0-9][0-9](?![0-9])
[0-9][0-9] could be also written as [0-9]{2}

hth,
Remas
http://www.aspalliance.com/remas/

--- Bob Levittan <Click here to reveal e-mail address> wrote:
[Original message clipped]

=====
Remas Wojciechowski
http://www.aspalliance.com/remas/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

| [aspngregexp] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngregexp.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification