Q:

Regex to insert dot (.)  after characters, before new line

I'm reformatting some text, and sometimes I have a string, where there is a sentence which is not ended by a dot. 
I'm running various checks for this purpose, and one more I'd like is to "Add dot after last character before new line". 
I'm not sure how to form the regular expression for this:]
$string = preg_replace("/???/", ".\n", $string);

A:

Try this one:
$string = preg_replace("/(?<![.])(?=[\n\r]|$)/", ".",  $string);

negative lookbehind (? <![.])  is checking previous character is not . 
positive lookahead (? =[\n\r]|$) is checking next character is a newline or end of string.