I read the mysql documentation about regexp but looks like the regexp can be used only as WHERE
filters to match rows in SELECT
query.
Im wondering if is possible to extract the matches of the regexp as columns, for example if in my table i have a SKU textfield with:
+----------------+--------------+---------------+
|sku | product_name | [other fields]|
+----------------+--------------+---------------+
|ART-2830--107-70| Foo | |
|ART-2832--115-6 | Bar | |
+----------------+--------------+---------------+
it would be great to fire a select query that matches the regexp (ART-)([0-9]+)(--)([0-9]+)(-)([0-9]+)
that gives me as output:
+------+------------+-------+----------+
| type | collection | model | material |
+------+------------+-------+----------+
| ART | 2830 | 107 | 70 |
| ART | 2832 | 115 | 6 |
+------+------------+-------+----------+
Please note that type, collection, model and material
columns are not present into my table, and are merely the matches of the regexp above.
Is this possible?
p.s: I know that would be a GREAT idea to normalize that table adding a column for each property i need, but this is the structure I have to work with and I can not edit this at the moment.
EDIT Just in case someone need this, I saw that PostgreSql offer this function.