# Having your clients write regular expressions

**URL:** <https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230>\
**Category:** Rails\
**Created:** [September 10, 2006, 10:20pm UTC](https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230 "2006-09-10T22:20:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [September 10, 2006, 10:20pm UTC](https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230/1 "2006-09-10T22:20:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [September 10, 2006, 10:51pm UTC](https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230/2 "2006-09-10T22:51:34Z")

</div>

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 🙂

> 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/](http://www.ruby-forum.com/).
> 
> >

–  
David A. Black | removed\_email\_address@domain.invalid  
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](http://www.manning.com/black) | [3] [http://www.rubypowerandlight.com](http://www.rubypowerandlight.com)  
[2] [http://dablog.rubypal.com](http://dablog.rubypal.com) | [4] [http://www.rubycentral.org](http://www.rubycentral.org)

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [September 10, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230/3 "2006-09-10T22:53:35Z")

</div>

Check out ez\_where,  
[http://www.brainspl.at/articles/2006/06/30/new-release-of-ez\_where-plugin](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

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [September 10, 2006, 11:27pm UTC](https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230/4 "2006-09-10T23:27:37Z")

</div>

Let them provide the SQL where clauses?

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [September 11, 2006, 12:01am UTC](https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230/5 "2006-09-11T00:01:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [September 11, 2006, 12:37am UTC](https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230/6 "2006-09-11T00:37:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [September 11, 2006, 12:50am UTC](https://www.ruby-forum.com/t/having-your-clients-write-regular-expressions/68230/7 "2006-09-11T00:50:40Z")

</div>

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.
