LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-30-2009, 11:16 PM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Absurd behavior of Regex


Hi all..

I have two files in the directory test named text[*?!1] and text[2*?!]

ls text*[!2-4]*
output is : text[*?!1] text[2*?!]

ls text*[!2-4]
output is : text[*?!1] text[2*?!]

In both the examples text[2*?!] should not appear, since i am trying to avoid numbers from 2 to 4.

why regex behaves like this ?

Any help will be greatly appreciated....
 
Old 09-30-2009, 11:34 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
What are the real, actual names, of these file in question, and what is it you expect to happen?? That would be handy in trying to diagnose what is the problem with the regex you are using.

Sasha
 
Old 09-30-2009, 11:48 PM   #3
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by GrapefruiTgirl View Post
What are the real, actual names, of these file in question, and what is it you expect to happen?? That would be handy in trying to diagnose what is the problem with the regex you are using.

Sasha
Thanks for you reply..

I am preparing for a certification..whatever names I have specified are the real name of files . In the output of both the ls commands I don't expect text[2*?!] in the output
 
Old 09-30-2009, 11:52 PM   #4
yai
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Rep: Reputation: 1
you do have weird filenames :-)
 
Old 09-30-2009, 11:54 PM   #5
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by yai View Post
you do have weird filenames :-)
But my point is how text[2*?!] is coming in both the outputs ..I am trying to avoid numbers form 2 to 4 by [!2-4]
 
Old 10-01-2009, 12:00 AM   #6
yai
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Rep: Reputation: 1
your "*" matches too many characters, try
ls text?[!2-4]*
 
Old 10-01-2009, 12:02 AM   #7
yai
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Rep: Reputation: 1
to be precise: your "*" matches Úverything to the end of the fileneme, that's why ls text*[!2-4]* and ls text*[!2-4] are equivalent.
 
Old 10-01-2009, 12:05 AM   #8
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by yai View Post
your "*" matches too many characters, try
ls text?[!2-4]*
Thanks a lot yai..It helped...
 
Old 10-01-2009, 12:24 AM   #9
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by vinaytp View Post
Thanks a lot yai..It helped...
Good! Please let us out of the suspense, and when you get this working, tell us what are the real filenames, and what you used as a regex, to make this work

Sasha
 
Old 10-01-2009, 12:33 AM   #10
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by GrapefruiTgirl View Post
Good! Please let us out of the suspense, and when you get this working, tell us what are the real filenames, and what you used as a regex, to make this work

Sasha
Hi GrapefruiTgirl

I have tried following...

[vinay@localhost temp]$ ls
text[*?!1] text[2*?!]
[vinay@localhost temp]$ ls text*[!2-4]*
text[*?!1] text[2*?!]
[vinay@localhost temp]$ ls text*[!2-4]
text[*?!1] text[2*?!]
[vinay@localhost temp]$ ls text?[!2-4]*
text[*?!1]

Last command solved my doubt....
 
Old 10-02-2009, 05:55 AM   #11
yai
LQ Newbie
 
Registered: Jun 2008
Posts: 19

Rep: Reputation: 1
Hi GrapefruiTgirl,
i couldn't beleive it at first, but these ARE his filenames, that's why i called them weird.

Code:
> "text[*?!1]"
> "text[2*?!]"

ll 

-rw-r-----   1 root       sys              0 Oct  2 12:51 text[*?!1]
-rw-r-----   1 root       sys              0 Oct  2 12:51 text[2*?!]
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with regex tbeehler Linux - Software 4 07-11-2008 10:05 AM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 05:10 AM
Regex help Penguin of Wonder Programming 4 08-06-2007 07:04 AM
LXer: UK firms contest 'absurd' software patent ruling LXer Syndicated Linux News 0 05-29-2007 11:16 AM
Absurd behaviour of KPPP dineshjk Red Hat 3 06-19-2004 11:43 PM


All times are GMT -5. The time now is 04:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration