the problem is that a single new line is a substring of double new lines. If you do the replacement for double new lines before the single new lines and then run the single new lines replacement, you should be fine.
In practice, this may get messy if you have new line chars separated by white space (spaces, tabs, etc.). It can also be complicated by the fact that there is the \r carriage return and the \n newline char (see wikipedia article on new line chars) and the fact that most newline files on a windows machine consist of both a \r and a \n character.
In practice, why do you need the </p> char for double new lines? Is there anything all that wrong with two newline chars in a row (</br></br>) ??