I have a list of alpha-numeric values that I need to search through using a “greater than or equal to” and/or “less than or equal to” operator.
Example list of values to be searched:
a
b
c
d
e
f
User enters b, and specifies to return everything “greater than or equal to” it.
Expected results:
b
c
d
e
f
What is the regular expression for this?
Edit: I’m suggesting regex because the users have the ability to enter wildcards.
P.S. This is not homework 🙂
Thanks in advance!
This isn’t something you should be using regular expressions for.
Iterate over the list and examine each item to see if is “greater than or equal to” the item the user provided. If you are using .NET 3.5 then you might find LINQ useful, and in particular the
Enumerable.Whereextension method.If you really want to use a regular expression you could use
[_-f]where the underscore must be replaced by the letter the user enters, but this only works on your specific example. Generalizing it to work with any strings of any length would be more complicated (and the resulting regular expression would be very messy).