Muhamad Muhamad - 3 years ago 109
MySQL Question

regular expression

I want to create regex to find single 1 from the flowing


  • 1,2

  • 2,1

  • 3,1,2

  • 7,171,818

  • 71,17,11

  • 1



Note : the needed mach is the bold in the prev list

JRG JRG
Answer Source

You can go with either approach ...

SELECT data FROM SAMPLE
WHERE data REGEXP '^1,|,1$|,1,|^1$'

enter image description here

SELECT * 
FROM sample
WHERE 
(data LIKE '1,%'
 OR
data LIKE '%,1'
 OR
data LIKE '%,1,%'
 OR
data LIKE '1')

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download