On 25 Feb 2001 14:37:02 -0800, Jeff Oien <[EMAIL PROTECTED]> wrote:
>> On 25 Feb 2001 10:34:27 -0800, Jeff Oien <[EMAIL PROTECTED]> wrote:
>> >I would like to get rid of \n characters unless there
>> >are two or more in a row. So for example if there
>> 
>> The Perl-compatible regular expressions support lookahead and look behind:
>> 
>> $str = preg_replace("/(?<!a)a(?!a)/", "-", $str);
>
>Man, that went right over my head. Is there a description of
>how this works anywhere? Thanks for help in any case.

The Regular Expression part of the online PHP manual has a lot of information
(http://www.php.net/manual/en/ref.pcre.php) but it does tend to assume you
already know what you need to do.

Basically, the regular expression in there matches any "a" where the character
before isn't an "a" (?<!a) and the character after isn't an a (?!a). Any
matched characters are replaced with hyphens. 

For your needs, '/(?<!\n)\n(?!\n)/m' should work (the /m turns on multi-line
support, which is necessary since we're working with line breaking characters).
Note that you'll need to escape those backslashes in PHP if you use
doublequotes.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to