469,282 Members | 1,923 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Regular expression weirdness with upper and lower case

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.

Jul 19 '05 #1
4 8469

se*****@concord.edu 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 df*****@mtxia.com
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

Jul 19 '05 #2

<se*****@concord.edu> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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
Jul 19 '05 #3

Matt Garrish wrote:
<se*****@concord.edu> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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.
**

Jul 19 '05 #4
wm********@tns.net 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
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Rajeev Soni | last post: by
3 posts views Thread by gimme_this_gimme_that | last post: by
4 posts views Thread by Chris | last post: by
18 posts views Thread by Lit | last post: by
1 post views Thread by AAaron123 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.