I found this query on GITHUB https://gist.github.com/matoakley/1092571 that converts strings into slugs, but I’m having problems when string contains EM and EN dashes, need help with this:
SELECT *, LOWER(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(TRIM(name), ':', ''), ')', ''), '(', ''), ',', ''), '\', ''), '/', ''), '\"', ''), '?', ''), ''', ''), '&', ''), '!', ''), '.', ''), ' ', '-'), '--', '-'), '--', '-')) as slug FROM program
SQL FIDDLE: http://sqlfiddle.com/#!9/511cc73/1
Result:
arrival-–-free-time-or-optional-activities
Need this Result: arrival-free-time-or-optional-activities
2
Answers
Tested on MySQL 8.0.32. The
REGEXP_REPLACE()
function is not implemented in earlier versions of MySQL.Reg_replace makes the query easier, so that you don_#t need for every pattern to add a new replace
Query 1:
Results: