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

 
 

bug #31933: Wrong results with negated -regex

Submitter:  Dario Niedermann <ndr>
Submitted:  Sun 19 Dec 2010 09:29:07 PM UTC
   
 
Category:  find Severity:  3 - Normal
Item Group:  Wrong result Status:  Invalid
Privacy:  Public Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  4.2.31 Fixed Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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>
Group 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 Files:
   
   
Comment:
   

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 jay (Posted a comment)
  • -email is unavailable- added by ndr (Submitted the item)
  •  

    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.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-12-19 jay StatusNone Invalid
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code