bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #16421] regexp bug in grep -P or libpcre


From: Tony Abou-Assaleh
Subject: Re: [bug #16421] regexp bug in grep -P or libpcre
Date: Mon, 8 Oct 2007 01:36:42 -0300 (ADT)

The example didn't come out right in the email, though they're displayed
fine on Savannah. The n's in the strings should be \n; i.e.,

--
$ printf "a\nb\n" | src/grep -P '[^a]'
a
b
$ printf "a\nb\n" | src/grep -P '^[^a]'
b
$ printf "a\nb\n" | src/grep -P '[^a]$'
b
$ printf "a\nb\n" | src/grep -P '[^a][^b]'
b
$ printf "a\nb\n" | src/grep -P '[\n]'
a
b
$ printf "a\nb\n" | src/grep -P '[^a][\n]'
b
--

Cheers,

TAA

-----------------------------------------------------
Tony Abou-Assaleh
Email:    address@hidden
Web site: http://tony.abou-assaleh.net
----------------------[THE END]----------------------

On Mon, 8 Oct 2007, Tony Abou-Assaleh wrote:

>
> Update of bug #16421 (project grep):
>
>                   Status:                    None => Confirmed
>
>     _______________________________________________________
>
> Follow-up Comment #1:
>
> I see similar behaviour in grep-2.5.3 and libpcre 6.7.
>
> Also:
>
> $ printf "anbn" | src/grep -P '[^a]'
> a
> b
> $ printf "anbn" | src/grep -P '^[^a]'
> b
> $ printf "anbn" | src/grep -P '[^a]$'
> b
> $ printf "anbn" | src/grep -P '[^a][^b]'
> b
> $ printf "anbn" | src/grep -P '[n]'
> a
> b
> $ printf "anbn" | src/grep -P '[^a][n]'
> b
>
> It appears that the end-of-line character is passed as part of the string and
> matched by [^a]. [^a] in PCRE will match an end-of-line character. From the
> pcrepattern man page:
>
> "The newline character is never treated in any special way in character
> classes, whatever the setting of the PCRE_DOTALL or PCRE_MULTILINE options is.
> A class such as [^a] will always match a newline."
>
> The question is: should grep pass end-of-line character of each line to PCRE?
> To be consistent, I think the answer is no.
>
> Care must be taken to handle -z and binary files properly.
>
>     _______________________________________________________
>
> Reply to this item at:
>
>   <http://savannah.gnu.org/bugs/?16421>
>
> _______________________________________________
>   Message sent via/by Savannah
>   http://savannah.gnu.org/
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]