473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 8661

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Toffe | last post by:
Hi, I've got a problem with regular expressions and strings containing Swedish characters (åäö). I basically have a PHP script that highlights certain words in a text. I found the code...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
8
by: Rajeev Soni | last post by:
Hi I am looking for the regular expression for validating the allowed file types to upload like files like "zip,pdf,doc,rtf,gif,jpg,png,txt"; and the expression should not be case sensitive like...
6
by: vvenk | last post by:
Hello: I am trying to learn about regular expressions. How would I use regular expressions to ensure that the password an user enters conforms to the following rules: 1. It has to be...
3
by: gimme_this_gimme_that | last post by:
What is the regular expression that checks that every character in a string is in ? Thanks.
2
by: Franky | last post by:
This should be easy to find but I've been looking and looking at the doc and can't find it. Maybe it can't be done. In the IDE editors find/replace I want to use regular expression to change the...
4
by: Chris | last post by:
I want to ensure a password has a least one lower case letter, one upper letter and a number. I'm a bit of a newbie but I understand you can use the pipe system for OR what about AND.I would like...
18
by: Lit | last post by:
Hi, I am looking for a Regular expression for a password for my RegExp ValidationControl Requirements are, At least 8 characters long. At least one digit At least one upper case character
1
by: AAaron123 | last post by:
I found this on the Internet and tried a few of them and they worked in VS2008. Actually it was in a different form but I converted to make a smaller file. The data is the same as the original. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.