0

I have a table colum with general text values ex:

"This is Gerald's Sample Text: With some special chars"

I need to convert this text to:

"this-is-geralds-sample-text-with-some-special-chars"

with MySQL InnoDB and save the value in a separate unique column in the same table. Is there a simpler way of achieving this with a query without using procedures?

ssrp
  • 1,126
  • 5
  • 17
  • 35

1 Answers1

1

The short answer is "No". You're looking for something that behaves exactly like a regular expression, and MySQL does not support regex replace natively.

The longer answer is "No, but there are workarounds." You have a couple of options, and I don't terribly like either. The first is to create a function like in this question. The second is to come up with a list of bad characters and then use a set of REPLACE calls. It's ugly, but it will work.

On a side note: you might consider creating this value with your application and then just store along with the original. That would be cleaner in some ways than using a custom MySQL function.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166