bugfindutils - Bugs: bug #31933, Wrong results with negated -regex

 
 

bug #31933: Wrong results with negated -regex

Submitted by:  Dario Niedermann <ndr>
Submitted on:  Sun 19 Dec 2010 09:29:07 PM UTC  
 
Category: findSeverity: 3 - Normal
Item Group: Wrong resultStatus: Invalid
Privacy: PublicAssigned to: None
Originator Name: Open/Closed: Closed
Release: 4.2.31Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Mon 20 Dec 2010 03:27:23 AM UTC, comment #2:

I find this very odd, since I did specify a '$' to match the end of filenames. Find's behaviour does not seem to be egrep-like since:

find . -type f | egrep -v '\.(css|png|gif)$'

returns the correct results.

Dario Niedermann <ndr>
Sun 19 Dec 2010 10:34:54 PM UTC, comment #1:

Your start point was ".". Hence all paths considered by find will be of the form "./" followed by something else. In other words they will match the regular expression '\./.*'. However, the regular expression you specified was '\.(css|png|gif)$' and that only matches filenames which have 'c', 'p' or 'g' in the second position. Since all filenames considered by find in this example have '/' in that position, no file names match the specified regex. It's negated, so the negated expression is always true and hence find will find all files.

I think you probably just misunderstood what -regex matches on:

$ PAGER="grep -A2 -e '-regex '" man find
-regex pattern
File name matches regular expression pattern. This is a match
on the whole path, not a search. For example, to match a file

James Youngman <jay>
Project Administrator
Sun 19 Dec 2010 09:29:07 PM UTC, original submission:

The following should find all files, except those ending in .css, .png, .gif :

<blockquote>
find . -type f -regextype posix-egrep '!' -regex '\.(css|png|gif)$'
</blockquote>

It simply finds all files instead.

Dario Niedermann <ndr>

 

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

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by jay (Posted a comment)
  • -unavailable- added by ndr (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 19 Dec 2010 10:34:54 PM UTCjayStatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1