buggrep - Bugs: bug #16421, regexp bug in grep -P or libpcre

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #16421: regexp bug in grep -P or libpcre

Submitter:  None
Submitted:  Sun 23 Apr 2006 01:22:36 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Confirmed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed

Fri 04 Dec 2009 08:03:04 PM UTC, comment #2: 

Duplicate of 17264.

Paolo Bonzini <bonzini>
Mon 08 Oct 2007 04:10:42 AM UTC, comment #1: 

I see similar behaviour in grep-2.5.3 and libpcre 6.7.

Also:

$ 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

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.

Tony Abou-Assaleh <taa>
Group administrator
Sun 23 Apr 2006 01:22:36 PM UTC, original submission:  

grep with -P options incorrectly process inversed character classes: [^...]
here is example:

$ cat test
a
b
$ grep '[a]' test
a
$ grep '[b]' test
b
$ grep '[^a]' test
b
$ grep '[^b]' test
a
$ grep -P '[a]' test
a
$ grep -P '[b]' test
b
$ grep -P '[^a]' test
a
b
$ grep -P '[^b]' test
a
b

I'm using:
grep-2.5.1
libpcre-6.3

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bonzini (Posted a comment)
  • -email is unavailable- added by taa (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-12-04 bonzini Open/ClosedOpen Closed
    2007-10-08 taa StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code