# Regexp in sql-statement

**URL:** <https://www.ruby-forum.com/t/regexp-in-sql-statement/138564>\
**Category:** Rails\
**Created:** [May 24, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/regexp-in-sql-statement/138564 "2008-05-24T20:13:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [May 24, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/regexp-in-sql-statement/138564/1 "2008-05-24T20:13:26Z")

</div>

Hi there…

easy question and I hope I will get an easy anwser…

I have in my database a table named “my\_table” and a column ‘my\_column’

in my\_column I have five entries as string

1. “123”
2. “123 45”
3. “45 123”
4. “12345”
5. “45123”

Now I need a sql-statement to select ONLY the datasets with “123” (this  
are the sets 1. 2. 3.)… before the “123” it can be that there is {0,}  
whitespaces… at the and of “123” the same…

but if i try

my\_request = myTable.find(:all, :conditions =\> ["my\_column REGEXP :test  
", {:test =\> “[]_123[]_”} ])

as the result I get all datasets… ☹

I used [] instead of \s because I donÂ´t know realy how to use the  
spezial characters in this statement

I there anyone who knows how to use regexp in find-statements?!?

thanks for helping

---

<div class="post-metadata">

**Author:** ![der\_guido](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@der\_guido](https://www.ruby-forum.com/u/der_guido)\
**Post date:** [May 24, 2008, 8:35pm UTC](https://www.ruby-forum.com/t/regexp-in-sql-statement/138564/2 "2008-05-24T20:35:46Z")

</div>

I found the answer…

my\_request = myTable.find(:all, :conditions =\> ["my\_column REGEXP :test

> ", {:test =\> “[[:\<:]]123[[:\>:]]”} ])

cheers guido

Guido Holz wrote:

> Hi there…
> 
> easy question and I hope I will get an easy anwser…
> 
> I have in my database a table named “my\_table” and a column ‘my\_column’
> 
> in my\_column I have five entries as string
> 
> 1. “123”
> 2. “123 45”
> 3. “45 123”
> 4. “12345”
> 5. “45123”
> 
> Now I need a sql-statement to select ONLY the datasets with “123” (this  
> are the sets 1. 2. 3.)… before the “123” it can be that there is {0,}  
> whitespaces… at the and of “123” the same…
> 
> but if i try
> 
> my\_request = myTable.find(:all, :conditions =\> ["my\_column REGEXP :test  
> ", {:test =\> “[]_123[]_”} ])
> 
> as the result I get all datasets… ☹
> 
> I used [] instead of \s because I donÂ´t know realy how to use the  
> spezial characters in this statement
> 
> I there anyone who knows how to use regexp in find-statements?!?
> 
> thanks for helping
