Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change   to space

I am developing a simple rich text editor by using contenteditable div. Now, I what I want is to change the   to a space.

I found this similar question How to replace   to space? in which the solution is to use REGEX but the answer doesn't provide any sample code and I really don't know how to use that.

I have this javascript code here:

if (e.keyCode == 32) {
    document.execCommand('inserText', false, ' ');
    return false;
}

In which as the user presses space, a space would insert as a text but by retrieving it, it's value is  

like image 450
Makudex Avatar asked Jan 07 '23 14:01

Makudex


1 Answers

Use the JavaScript replace function using Regex with the global flag:

str.replace(/ /g, ' ');
like image 159
Nerdwood Avatar answered Jan 19 '23 00:01

Nerdwood