REGEXP to select data

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have data in a row, such as "34,54,12,134"

I need to select rows where they match certain numbers, and not others,
so match 34,12 and not 134 (ie the above row would fail, but
"34,124,12" would pass).

How do I build a REGEXP to search this - I've tried
(^34|,34,|,34$) - but that only works to find one match. How do I "AND"
in the REGEXP (regardless of order) and exclude a term?

Maybe there is a much better way of doing this?

Many thanks

Re: REGEXP to select data


I have managed to refine the REGEXP selection a little, but I think I
am not combining the regexp correctly - I know have something like:

SELECT meal FROM recipe WHERE ingrediants REGEXP '(^|,)apple(,|$)'
REGEXP '(^|,)pepper(,|$)' NOT REGEXP '(^|,)nuts(,|$)

The data looks something like:

apple,pepper,carrots (so true)
nuts,apples,pepper (so false)

Site Timeline