match_replace for every instance forever
- Posted by euphoric (admin) Nov 08, 2011
- 1294 views
I want to turn all multiple space sequences in a string to a single space. For example:
x = match_replace( " ","a b c d e f g h"," ") -- so x should be "a b c d e f g h"
I thought we had a match_count() function, but can't find anything like that in the manual. I figured I could loop
while match_count(" ",x) > 0 do x = match_replace( " ",x," ") end while
Or maybe match_replace() can be made to be recursive, but I don't see a flag for that. (In fact, the docs state "Replacements will not be made recursively on the part of haystack that was already changed." Maybe we could change that?)
Or... anybody know how to do this most quickly and efficiently?