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
Use the JavaScript replace
function using Regex with the global flag:
str.replace(/ /g, ' ');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With