a <- "\n \n \n \nTEST TEST\n"stringr::str_replace_all(a, "(?m)^\\h+$", "")
Standard input is empty
[1] "\n\n\n\nTEST TEST\n"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!