. . .

MySQL Regexp to match a number from comma separated list of numbers

Published: October 14, 2010

On This Page

    I have found regexp select statements useful for databases which have fields of comma-separated numbers. If I need to select all rows with a given number in such a comma-separated list, a regular expression using word boundries would work:

     

    [[:<:]] left word boundary
    [[:>:]] right word boundary

     

    The below will locate all rows with number "23" in their comma-seperated list:
    mysql> select id,photos from categories where photos regexp "[[:<:]]23[[:>:]]";

     

    Source: http://www.phototour.minneapolis.mn.us/linux/regexp

    Don't forget to share this post

      Let's Build Digital Excellence Together


      • Cost Efficient Solutions.
      • Minimal Timelines.
      • Effective Communication.
      • High Quality Standards.
      • Lifetime Support.
      • Transparent Execution.
      • 24/7 Availability.
      • Scalable Teams.

      Join Our 200+ Happy Clients Across Globe


      Free Consultation.

        Do you need tech help of your startup/business? Experts from our team will get in touch with you.

        Please do not post jobs/internships inquiries here.