Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search using Regular Expression

Status
Not open for further replies.

filp530

Programmer
Jun 20, 2003
6
0
0
US
Is it possible to search a range of numbers in the Regular Expression object?

Example: 1234.12
1234.13
1234.16
1234.20

If anybody can help, I would gladly appreciate it.


Vance
 
Depends what you're trying to do. For a start, the number must be in a string. Secondly, the way you've presented your example suggests to me that you have an array. Since RegExp wants text input, you'd have to Join() your array. And that will probably be leading you away from anywhere that I can guess you might want to be.

More info on the problem would be useful...

;-)

Mike
 
Mike,

What I'm trying to do is using the regular expression to search for a decimal number in a certain range. For instance 1234.12. I would like to look for numbers that are about the +.1 to -.1 range. I wonder if you can find 1234.13, 1234.14, 1234.15, 1234.19, 1234.20. Something like that. If you could help me out, I would really appreciate that.

Vance
 
How are the numbers stored, and in what format? If these numbers are in a database, stored as type Float (or Single/Double), then you can use a SQL statement such as:

Select * From Table Where Number is between 1234.02 and 1234.22

Doing this with regular expressions is much harder, as you need to account for number wrap (if number is 2.02, then range is 1.92 - 2.12). So to do the comparison with regular expressions, you need check for 3 different conditions and use a different regular expression for each.
 
Hi,
Create a class Class1 with a constructor in which you pass the the range you want.
Add method like bool CheckInRange (string expr) in which you do:
-use regular expresion object to match the expr with a decimal number.
-if no match return false
-if match then extraxt the decimal number and check if it is in the range.

-obislavu-

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top