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




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com