s/(~+)/$1\n/g;
Another variant would be to use the (relatively new) \K ("Keep the stuff left of the \K"), which avoids having to capture/re-insert the matched fragment:
s/~+\K/\n/g;
In reply to Re^2: regex replacement help
by Eliya
in thread regex replacement help
by mkenney
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |