Is there a way to add a space after commas in a string only if it doesn't exist.
Example:
word word,word,word,
Would end up as
word word, word, word,
Is there a function in ruby or rails to do this?
This will be used on hundreds of thousands of sentences, so it needs to be fast (performance would matter).
Using negative lookahead to check no space after comma, then replace with comma and space.
print 'word word,word,word,'.gsub(/,(?![ ])/, ', ')
1.4m articles
1.4m replys
5 comments
57.0k users