473,547 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8673

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.c om
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*****@concor d.edu> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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*****@concor d.edu> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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
8192
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 attached below in the commented manual at php.net. It works great for all words that do not contain Swedish characters. The words that do contain åäö will...
1
4156
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 regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) ...
8
7309
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 it must match ZIP | zip | zIp..... regards rajeev
6
1210
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 between 3-20 characters long. 2. Only a-z, A-Z, 0-9, +-_ are allowed. 3. At least one occurence of a lower case letter, a upper case letter and a
3
1284
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
1934
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 first letter after "Dim " to lower case. e.g Dim Tmp to Dim tmp can you show me the replace string.
4
4724
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 something like this. &&
18
622
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
1576
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. I'm confused about how regular expressions work in different systems. I suspect that each system may have some things that do not work in other...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7461
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.