I want to search and replace some digits in a
text file and that are separated by spaces and
merge them together
like
asdf asdf 1 2
3 asdf asdf asdf
2 3 asdf
to
asdf asdf 123
asdf asdf asdf
23 asdf
I tried the following, but it doesn’t work, and I am not sure how to best do the replacing in the file:
text = File.read("testfile.txt")
p text.scan(/([\d+\s+\d+]+)/)
1 Answer