views:

42

answers:

2

I want to do a MySQL query to get the following effect:

table_column [varchar]
-----------------------
   1|5|7
      25
   55|12
       5
     3&5
    5|11

I want a reliable way to get all the values where 5 is the complete value.

So, for example, if I do a REGEXP query for the number 5 on the upper table I would like to get all rows except the ones containing "25" and "55|12".

This is the best I've come up with so far:

[^[:digit:]]5[^[:digit:]] | [^[:digit:]]5 | 5[^[:digit:]] | ^5$

is there a shorter way?

Thanks.

A: 

Try using word boundaries:

[[:<:]]5[[:>:]]
Amber
A: 
^.*[^[:digit:]]*5[^[:digit:]]*.*$
Paul Creasey
Won't work. That expression matches `55`, for instance (keep in mind that the `*` operator can match 0 of an item as well...).
Amber
capture the central 5 and it works..
Paul Creasey