I want to create a regex to find a single 1 from the flowing
the following list is the sample of the column value I like to search in
- 1,2
- 2,1
- 3,1,2
- 7,171,818
- 71,17,11
- 1
Note: the needed match is bolded in the prev list
Advertisement
Answer
You can go with either approach …
x
SELECT data FROM SAMPLE
WHERE data REGEXP '^1,|,1$|,1,|^1$'
SELECT *
FROM sample
WHERE
(data LIKE '1,%'
OR
data LIKE '%,1'
OR
data LIKE '%,1,%'
OR
data LIKE '1')