I’d like to split a string in MySQL using a regex delimiter. Is there any way this could be done?
I found this blog post explaining how to implement a simple split string function:
mysql split string function
However, i have to split my string by two alternative characters, so i would want to use this regex: [-,] to separate the string.
Here is an example of the table i have and what i want to achieve:
| id | range |
|----|-------|
| 1 | 2,3,5 |
| 2 | 1-4 |
| 3 | 2 |
What i want to do is finding the min and max values of each “range”-field.
So, i would like to get:
Row 1: 2 and 5
Row 2: 1 and 4
Row 3: 2
Any hints would be much appreciated!
Considering your table name is named
dataand the values inrangeare sorted from the minimum to the maximum, would it be ok?However you should really think about creating a new table for the ranges as Boris suggested it, it would be cleaner if you can.