I need to replace “\n” characters to ” ” if it’s standing alone.
I have a string like:
“Hello\n Stack\n\n\nover\nflow”
And it should be replaced with:
“Hello Stack\n\n\nover flow”
I’ve tried on ruby something like this:
> "Hello\n Stack\n\n\nover\nflow".gsub(/\n(?![\n])/, " ")
=> "Hello Stack\n\n over flow"
But it saves an extra “\n”
Im guessing you need something like
/(?<!\n)\n(?!\n)/. To check that there is no\nbefore or after the matching one.Thanks @JohnySkovdal for the correction