ReplaceAllAllAll?

I’m having trouble getting rid of ‘repeating’ characters like spaces in a line…

dim s as string = "three spaces two spaces one space" s = s.ReplaceAll(" ", " ")

Ok… I know I’m pushing my luck but the above code replaces two spaces with one space.
If there are three spaces I want it replaced by 1 space… So I thought replacing two spaces with one would always do the trick… but it don’t.

dim rxSqueezeSpaces as new RegEx
rxSqueezeSpaces.SearchPattern = "\\x20{2,}"
rxSqueezeSpaces.ReplacementPattern = " " // Space
rxSqueezeSpaces.Options.ReplaceAllMatches = true

s = rxSqueezeSpaces.Replace( s )

My M_String module and StringUtils also have pretty fast Squeeze functions. (I think I lifted the one in StringUtils, IIRC.)

While InStrB(s, " ") s = s.ReplaceAllB(" ", " ") Wend

[quote=422079:@Kem Tekinay] rxSqueezeSpaces.SearchPattern = "\\x20{2,}"
[/quote]

Can someone explain that SearchPattern to me???

SPACE (Whitespace?)

2 times or more

Found it:

\xnn Replaced with the character represented by nn in Hex, e.g., ™is ™.

Though that example in the language reference seems wrong …

I prefer that form rather than just using the invisible space.