Can I match and replace a text pattern in a MYSQL select?
EDIT For now it looks like the answer is: Can't be done, since you can't capture what was matched (from Eric's answer / comments). For now I will look into adding a lookup table.
Simplified example:
The MySQL table Coleridge holds many strings like:
text
------------------------------------
In_Xanadu_did_Kubla_Khan
A_stately_pleasure_dome_decree
Where_Alph_the_sacred_river_ran
Through_caverns_measureless_to_man
Down_to_a_sunless_sea
Is there a way to express the select
SELECT text =~ s / [ ^_ ] + _ ( .* ) _ [ ^_ ] + $ / \1 / as replaced FROM Coleridge
and get
replaced
________________________
Xanadu_did_Kubla
stately_pleasure_dome
Alph_the_sacred_river
caverns_measureless_to
to_a_s
Please Note:
- The regular expression s/ / / I provided is much less complicated than what the real world DB contains
- Unfortunately I can't normalize the DB ..