I'm trying to match any character except for ">" followed by a new line. So this is the pattern I used: "/[>]\n/" It works, and I'm using it in a preg_replace function to strip the new line, but I want to preserve the character before the new line. So basically "Hello\ntesting" would become "Helltesting". Is there anything I can do to the pattern to achieve this?
Use a backreference...
preg_replace("/([^>])\n/", "$1", $contents);
Another approach, though not necessarily better or worse, would be to use a look-behind assertion:
preg_replace('/(?<!>)\n/', '', $string);