text = "Math\n \n \n 600 rubles / 45 min."gsub("(?:\n {6,}){3}(\\d)", " \\1", text)
Standard input is empty
[1] "Math 600 rubles / 45 min."
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!