Search code examples
mysqlmariadbregexp-replace

Remove all whitespaces between non words?


How can I remove all spaces between non words from a column? I have a column with values like that:

"This Is My - Value"
"This Is My- Value"
"This Is My/ Value"
"This Is My- Value (Other -Value)"

How can I remove all whitespaces between non words, like so:

"This Is My-Value"
"This Is My-Value"
"This Is My/Value"
"This Is My-Value(Other-Value)"

Tried this, but is not working:

SELECT REGEXP_REPLACE(I,"\s*([^a-zA-Z\d\s:])\s*","\\1") FROM registros;

Solution

  • Got it:

    SELECT REGEXP_REPLACE(I,"\[[:blank:]]*([-/()])\[[:blank:]]*","\\1") FROM registros;