Hello

I need to use MySQL's REGEXP (POSIX compliant) to search registries where one field is an imploded set of integer values separated with pipes "|".
I need to match one of these imploded values directly on a sql select.
$sql = "SELECT FROM table WHERE imploded REGEX "????" . $number . "????";

Example, with the string "10|3|605|40" I need to match 605 but not 5, match 40 but not 4, match 10 but not 1...
I'm not expert in regular expressions and I can't find the proper one.

Any help?

Thanks in advance

    you probably don't ned to use REGEX at all in this case. For example if you need to match 105 use LIKE '%|105|%'. of course this entails that you save your data with pipes on the ends as well. If that is not possible, then I'm sure I coudl help you out with the REGEX

      I think it could work (hope not to mess the results in other parts of the program where I explode, and work with arrays).

      Anyway, I still curious about REGEX method, it could be useful in the future.

      I don't know how to build a expression saying:
      (start of string | [0-9])605([0-9] | end of string)
      or
      (start of string | |)605(| | end of string)

        Yes, the LIKE workaround works just ignoring the empty array values.

        But what if you're looking in a CSV file line.
        A regular expression should be very valuable.

        Any idea?

          Write a Reply...