Re: regex problem

From: Date: Thu, 01 Jul 2004 22:25:49 +0000
Subject: Re: regex problem
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-189495@lists.php.net to get a copy of this message
Why is it taking the char before the [^\r] also? -Josh On Thu, 1 Jul 2004 15:17:04 -0700, Justin Patrin <papercrane@gmail.com> wrote: > > On Thu, 1 Jul 2004 16:41:50 -0500, Josh Close <narshe@gmail.com> 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 = preg_replace("/([^\r])\n/i","\\1\r\n",$string); > > You could also use forward look-aheads, but I don't remember how to do > that right now. > > > $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 > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > !DSPAM:40e48327189276451316304! > > > > > > > -- > DB_DataObject_FormBuilder - The database at your fingertips > http://pear.php.net/package/DB_DataObject_FormBuilder > > paperCrane --Justin Patrin-- >

« previous php.general (#189495) next »