.NETGURU
How to match a range of numbers?
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.

Oskar Sandwall

What I want to do is to match integers between 0 to 3567.

I have problem doing this since i only know how to match
numbers between 0 and 9999 "^[0-9]{1,4}".

Can anyone help me... or tell me its impossible? :)

Thank you!

................................................................
SVERIGES ENKLASTE E-POSTADRESS! - http://www.sverige.nu
SVERIGES NYA ADRESSREGISTER! - http://www.adress.nu

Reply to this message...
 
    
Scott (VIP)
The only way I know how to do it is to make essentially several matches.
Something like : (this is off the top of my head, but it should be
close)

([0-2][0-9]{0,3})|(3[0-4][0-9][0-9])|(35[0-5][0-9])|(356[0-7])

The first part matches everything from 0 to 2999. The second part
matches everything from 3000 - 3499, part 3 matches 3500 - 3559, the
last part matches 3560 - 3569.

Scott Swigart
3 Leaf Solutions, LLC
www.3leaf.com
503-281-9681

-----Original Message-----
From: Oskar Sandwall [mailto:Click here to reveal e-mail address]=20
Sent: Thursday, November 01, 2001 7:15 AM
To: aspngregexp
Subject: [aspngregexp] How to match a range of numbers?

What I want to do is to match integers between 0 to 3567.

I have problem doing this since i only know how to match numbers between
0 and 9999 "^[0-9]{1,4}".

Can anyone help me... or tell me its impossible? :)

Thank you!

................................................................
SVERIGES ENKLASTE E-POSTADRESS! - http://www.sverige.nu=20
SVERIGES NYA ADRESSREGISTER! - http://www.adress.nu

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

Reply to this message...
 
    
Benjamin D. Gray
Something like this might work for you:
"(3[0-4][0-9]{2})|(35[0-5][0-9])|(356[0-7])|([1-2][0-9]{3})|([0-9]{1,3})
"

bdgray

-----Original Message-----
From: Oskar Sandwall [mailto:Click here to reveal e-mail address]
Sent: Thursday, November 01, 2001 8:15 AM
To: aspngregexp
Subject: [aspngregexp] How to match a range of numbers?

What I want to do is to match integers between 0 to 3567.

I have problem doing this since i only know how to match
numbers between 0 and 9999 "^[0-9]{1,4}".

Can anyone help me... or tell me its impossible? :)

Thank you!

................................................................
SVERIGES ENKLASTE E-POSTADRESS! - http://www.sverige.nu=20
SVERIGES NYA ADRESSREGISTER! - http://www.adress.nu

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

Reply to this message...
 
    
Wayne King
Here's a slightly different pattern along the same lines (spaces added =
to expression for clarity):
^( \d{1,3} | [0-2]\d{3} | 3[0-4]\d{2} | 35[0-5]\d | 356[0-7] )$

You could reduce this expression down a few different ways to make it a =
little more efficient. One obvious way is:
^( \d{1,3} | [0-2]\d{3} |
3 ([0-4]\d{2} |=20
5 ([0-5]\d | 6[0-7] )
)
)$

When you use the expression, use the RegexOptions.ExplicitCapture =
option, and if you leave the whitespace or newlines include =
RegexOptions.IgnorePatternWhitespace.

-----Original Message-----
From: Scott [mailto:Click here to reveal e-mail address]
Sent: Thursday, November 01, 2001 8:16 AM
To: aspngregexp
Subject: [aspngregexp] RE: How to match a range of numbers?

The only way I know how to do it is to make essentially several matches.
Something like : (this is off the top of my head, but it should be
close)

([0-2][0-9]{0,3})|(3[0-4][0-9][0-9])|(35[0-5][0-9])|(356[0-7])

The first part matches everything from 0 to 2999. The second part
matches everything from 3000 - 3499, part 3 matches 3500 - 3559, the
last part matches 3560 - 3569.

Scott Swigart
3 Leaf Solutions, LLC
www.3leaf.com
503-281-9681

-----Original Message-----
From: Oskar Sandwall [mailto:Click here to reveal e-mail address]=20
Sent: Thursday, November 01, 2001 7:15 AM
To: aspngregexp
Subject: [aspngregexp] How to match a range of numbers?

What I want to do is to match integers between 0 to 3567.

I have problem doing this since i only know how to match numbers between
0 and 9999 "^[0-9]{1,4}".

Can anyone help me... or tell me its impossible? :)

Thank you!

................................................................
SVERIGES ENKLASTE E-POSTADRESS! - http://www.sverige.nu=20
SVERIGES NYA ADRESSREGISTER! - http://www.adress.nu

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

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

Reply to this message...
 
 
System.Text.RegularExpressions.RegexOptions




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