Regular expression weirdness with upper and lower case

S

semovrs

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.
 
M

Matt Garrish

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
 
D

dfrench

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 (e-mail address removed)
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
 
W

wmreinemer

Matt said:
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.
**
 
J

Jürgen Exner

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top