The problem was solved by writing a correct regexp
let remove_newlines (str : string) : string =
let regex = Str.regexp "\n\\([a-z]\\)" in
Str.global_replace regex " \\1" str
It turned out that it was my own problem for not having a good understanding of how to use regex. Sad!