import res = "this is a sample\\nstring\\\\ncontaining\nall cases and one more\\n\nadded"print(re.sub(r"(?<!\\)\\n|\n", "<br>", s))
Standard input is empty
this is a sample<br>string\\ncontaining<br>all cases and one more<br><br>added
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!