0

Hi I am new to Mysql and Regexp and wanted help in running the below regexp to clear whitespaces from a column called description in my table.

string = string.replace(/\s{2,}/g, ' ');

Can someone please help? I can do basic query's.

3
  • Do you absolutely want to use regex ? Commented Jun 10, 2013 at 20:42
  • stackoverflow.com/questions/986826/… Commented Jun 10, 2013 at 20:43
  • No i am open to suggestions i want to remove all white spaces apart from one whitespace thats why i though Regexp was best. Commented Jun 10, 2013 at 20:47

1 Answer 1

2

No need for RegEx in that case.
You can simply use the Trim() function from mySQL.

It will simply remove all the white spaces :

SELECT TRIM('      removeSpaces      ');
--------

OUTPUT : [removeSpaces]   
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry I want to keep one space not remove all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.