You want a negative lookbehind assertion. like so: #!/usr/bin/php -q <? $string = "hello\nworld\n"; $string = preg_replace("/(?<!\r)\n/i","\r\n",$string); $string = addcslashes($string, "\r\n"); print $string; ?> Otherwise you're matching any character before a \n that's not a \r and replacing it. jonner On Thu, 2004-07-01 at 16:54, Josh Close wrote: > I'm trying to get a simple regex to work. Here is the test script I have. > > #!/usr/bin/php -q > <? > > $string = "hello\nworld\n"; > $string = preg_replace("/[^\r]\n/i","\r\n",$string); > $string = addcslashes($string, "\r\n"); > > print $string; > > ?> > > This outputs > > hell\r\nworl\r\n > > so it's removing the char before the \n also. > > I just want it to replace a lone \n with \r\n > > -Josh > > _______________________________________________ > TCLUG Mailing List - Minneapolis/St. Paul, Minnesota > Help beta test TCLUG's potential new home: http://plone.mn-linux.org > Got pictures for TCLUG? Beta test http://plone.mn-linux.org/gallery > tclug-list at mn-linux.org > https://mailman.real-time.com/mailman/listinfo/tclug-list -- jonathon jongsma _______________________________________________ TCLUG Mailing List - Minneapolis/St. Paul, Minnesota Help beta test TCLUG's potential new home: http://plone.mn-linux.org Got pictures for TCLUG? Beta test http://plone.mn-linux.org/gallery tclug-list at mn-linux.org https://mailman.real-time.com/mailman/listinfo/tclug-list