LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Absurd behavior of Regex (https://www.linuxquestions.org/questions/linux-newbie-8/absurd-behavior-of-regex-758826/)

vinaytp 09-30-2009 11:16 PM

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

GrapefruiTgirl 09-30-2009 11:34 PM

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

vinaytp 09-30-2009 11:48 PM

Quote:

Originally Posted by GrapefruiTgirl (Post 3702787)
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

yai 09-30-2009 11:52 PM

you do have weird filenames :-)

vinaytp 09-30-2009 11:54 PM

Quote:

Originally Posted by yai (Post 3702802)
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]

yai 10-01-2009 12:00 AM

your "*" matches too many characters, try
ls text?[!2-4]*

yai 10-01-2009 12:02 AM

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.

vinaytp 10-01-2009 12:05 AM

Quote:

Originally Posted by yai (Post 3702810)
your "*" matches too many characters, try
ls text?[!2-4]*

Thanks a lot yai..It helped...

GrapefruiTgirl 10-01-2009 12:24 AM

Quote:

Originally Posted by vinaytp (Post 3702820)
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

vinaytp 10-01-2009 12:33 AM

Quote:

Originally Posted by GrapefruiTgirl (Post 3702841)
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....

yai 10-02-2009 05:55 AM

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*?!]



All times are GMT -5. The time now is 05:41 AM.