I’m currently making plugin, and for it to work perfectly, I need to do following things to TextBoxes:

Remove trailing and leading spaces (I know how to do this, but is there a way to combine the pattern?)

Allow only 1 space per word
I’ll write [n spaces] because I cant write more that 1 space per word here.
For example:
a[2 spaces]b
→ a[1 space]b
(remove 1 space as there were 2 spaces)
a[1 spaces]b
→ a[1 space]b
(no changes as there was 1 space)
[1 space]a[3 spaces]b[4 spaces]
→ [0 spaces]a[1 space]b[0 spaces]
(remove leading and trailing spaces + remove 2 spaces between a
and b
as there were 3 spaces)
Note that TextBox is not limited to 2 words in my plugin.