Having your clients write regular expressions

I’m sure the last thing you would want your client to do is lear regular
expressions and how to write them. I have a scenario where I need to
filter results retireved from my program. The results can contain
letters, numbers, or both. The problem is that he needs to filter them
using ranges, exact matches, etc. Obviously regular expressions can do
this.

Here is my main problem: He needs to do 15-90. You can’t do 15-90 in a
regular expression.

Basically I need an alternative to regular expressions that my client
can understand, but still gives him the ability to do some complex
comparisons.

Any ideas?

Thanks for your help.

Hi –

On Sun, 10 Sep 2006, Ben J. wrote:

I’m sure the last thing you would want your client to do is lear regular
expressions and how to write them. I have a scenario where I need to
filter results retireved from my program. The results can contain
letters, numbers, or both. The problem is that he needs to filter them
using ranges, exact matches, etc. Obviously regular expressions can do
this.

Here is my main problem: He needs to do 15-90. You can’t do 15-90 in a
regular expression.

Do you mean matching any integer from 15-90? If so, you could use
something like:

/\b(?:1[5-9])|(?:[2-8][0-9])|90\b/

But I can understand that you don’t expect your client to come up with
that :slight_smile:

Basically I need an alternative to regular expressions that my client
can understand, but still gives him the ability to do some complex
comparisons.

Any ideas?

There was a library called Regexp::English, by Florian G., though I
can’t find it any more. I’m not sure whether it would help,
though… It gives you an English-language way to build patterns,
but you still have to know what you’re building.

I suspect you might be best off creating some kind of little wrapper
language yourself.

David

Thanks for your help.


Posted via http://www.ruby-forum.com/.


David A. Black | [email protected]
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]
[1] Ruby for Rails | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com | [4] http://www.rubycentral.org

Check out ez_where,
http://www.brainspl.at/articles/2006/06/30/new-release-of-ez_where-plugin

It might help with you range problem

or you could do

/(1[5-9]|[2-8]\d|90)/ which might not be the best way of matching that
but i
believe it’ll work

Let them provide the SQL where clauses?

It could be a Very Bad Idea, but either way the plugin’s really nifty.

Ian L. wrote:

Let them provide the SQL where clauses?

What I’m doing doesn’t interact with the database at all. I just need to
filter results that I retrieve. I have no control over what I receive,
which is why I need to filter with regular expressions.

Ben J. wrote:

Ian L. wrote:

Let them provide the SQL where clauses?

What I’m doing doesn’t interact with the database at all. I just need to
filter results that I retrieve. I have no control over what I receive,
which is why I need to filter with regular expressions.

Regexps cannot do everything for you. Use the regexp to
find out whether there are numbers and then match against
a Range constructed from the 15-19 syntax.