Regular expression weirdness with upper and lower case

Discussion in 'Perl' started by semovrs@concord.edu, Dec 6, 2004.

  1. Guest

    Hello, everyone!
    I would appreciate any input or advice on the following quite simple
    issue:
    If I search through a file list using grep -E '.*[^(JPG|png)]$' it will
    not pull files ending in JPG and files ending in png which is fine.
    However, I have some files ending in jpg (note - lower case) and it
    will not display them either. Why is that? Am I doing something wrong
    here and if so - what?
    It obviously is a regexp issue and not a grep issue because I tried
    this in vim and it acts the same way.
    Any advice would be greatly appreciated.
    Thanks,
    Roumen.
    , Dec 6, 2004
    #1
    1. Advertising

  2. Matt Garrish Guest

    <> wrote in message
    news:...
    > Hello, everyone!
    > I would appreciate any input or advice on the following quite simple
    > issue:
    > If I search through a file list using grep -E '.*[^(JPG|png)]$' it will
    > not pull files ending in JPG and files ending in png which is fine.
    > However, I have some files ending in jpg (note - lower case) and it
    > will not display them either. Why is that? Am I doing something wrong
    > here and if so - what?
    > It obviously is a regexp issue and not a grep issue because I tried
    > this in vim and it acts the same way.
    > Any advice would be greatly appreciated.
    >


    Probably because you're not doing what you think you're doing. You're
    creating a negated *character class* and checking for files that don't end
    with one of those characters. You're not looking for files that don't end in
    JPG or png, even though that might seem to be working. And since .jpg end
    with "g"...

    Since you're not asking a Perl question, I'll leave it to you to make it
    work for grep.

    Matt
    Matt Garrish, Dec 6, 2004
    #2
    1. Advertising

  3. Guest

    wrote:
    > Hello, everyone!
    > I would appreciate any input or advice on the following quite simple
    > issue:
    > If I search through a file list using grep -E '.*[^(JPG|png)]$' it

    will
    > not pull files ending in JPG and files ending in png which is fine.
    > However, I have some files ending in jpg (note - lower case) and it
    > will not display them either. Why is that? Am I doing something wrong
    > here and if so - what?

    SNIP

    The regexp you specified says the following:

    any single character - 0 or more times, followed by
    any single character from the set of characters between
    the square brackets that is NOT an open paren, or J,
    or P, or G, or |, or p, or n, or g, or close paren,
    followed by an end-of-line.

    I think what you want is:

    egrep -iv 'JPG$|png$'

    --
    Dana French - Mt Xia
    Mt Xia Technical Consulting Group http://www.mtxia.com
    Ridmail - 100% Spam Free Email http://www.ridmail.com
    MicroEMACS Binaries http://uemacs.tripod.com
    Korn Shell Web http://dfrench.tripod.com
    , Dec 6, 2004
    #3
  4. Guest

    Matt Garrish wrote:
    > <> wrote in message
    > news:...
    > > Hello, everyone!
    > > I would appreciate any input or advice on the following quite

    simple
    > > issue:
    > > If I search through a file list using grep -E '.*[^(JPG|png)]$' it

    will
    > > not pull files ending in JPG and files ending in png which is fine.
    > > However, I have some files ending in jpg (note - lower case) and it
    > > will not display them either. Why is that? Am I doing something

    wrong
    > > here and if so - what?
    > > It obviously is a regexp issue and not a grep issue because I tried
    > > this in vim and it acts the same way.
    > > Any advice would be greatly appreciated.
    > >

    >
    > Probably because you're not doing what you think you're doing. You're


    > creating a negated *character class* and checking for files that

    don't end
    > with one of those characters. You're not looking for files that don't

    end in
    > JPG or png, even though that might seem to be working. And since .jpg

    end
    > with "g"...
    >
    > Since you're not asking a Perl question, I'll leave it to you to make

    it
    > work for grep.
    >
    > Matt

    **
    You are right, It is a regex issue.

    to search for a *.jpg and *.png try

    grep *.[jp][pn]g

    to include search for upper and lower case in the extension:
    grep *.[JjPp][PpNn][Gg]

    Walt R.
    **
    , Dec 7, 2004
    #4
  5. wrote:
    > You are right, It is a regex issue.
    >
    > to search for a *.jpg and *.png try
    >
    > grep *.[jp][pn]g


    Are you sure you want to include *.jng and *.ppg in your list of matching
    file extensions, too?

    > to include search for upper and lower case in the extension:
    > grep *.[JjPp][PpNn][Gg]


    I would rather use the /i option.
    From "perldoc perlop":
    Options are:
    [...]
    i Do case-insensitive pattern matching.

    jue
    Jürgen Exner, Dec 7, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Janice

    lower case to upper case

    Janice, Dec 10, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,162
    Richard Bos
    Dec 14, 2004
  2. Peter Vanderhaden
    Replies:
    5
    Views:
    123
    SpringFlowers AutumnMoon
    Sep 30, 2007
  3. Replies:
    4
    Views:
    116
    Jürgen Exner
    Dec 7, 2004
  4. penny
    Replies:
    28
    Views:
    2,357
    Charlton Wilbur
    Mar 10, 2008
  5. BlackHelicopter
    Replies:
    0
    Views:
    503
    BlackHelicopter
    Jan 31, 2013
Loading...

Share This Page