LinuxQuestions.org
Visit Jeremy's Blog.
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 07-19-2003, 01:37 AM   #1
lido
Member
 
Registered: Jul 2003
Posts: 34

Rep: Reputation: 15
wildcard vs regular expression


Hi,

I've come across the term wildcard and regular expression. Both looks very similar, thus very confusing. may I know what's the difference between these two?

Thank You very much
 
Old 07-19-2003, 02:12 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
They have a slight similarity, however,
regexp are way more powerful. A wildcard
is ie an * and replaces any sequence of
characters. Regexps allow for differnt setups,
like explicitly searching for numeric components
and such.

Cheers,
Tink

Last edited by Tinkster; 09-02-2004 at 08:58 PM.
 
Old 07-19-2003, 02:31 AM   #3
lido
Member
 
Registered: Jul 2003
Posts: 34

Original Poster
Rep: Reputation: 15
Hi,

I have a question which I'm not sure if my ans is right.

For example if a directory contains the following files, what's the command to list the files ending with a number less than 3 and the command to list the files ending with any single digit number.

The files as follows
abc1
abc2
abc3
abc11

My ans for the question is ls *[0-2], but it list the file abc11 as well. Is there any more specific command to both the questions shown above?


Thanks you very much
 
Old 07-19-2003, 10:55 AM   #4
lido
Member
 
Registered: Jul 2003
Posts: 34

Original Poster
Rep: Reputation: 15
Hi,

Does anyone have any idea how it can be done?

Apprecite if someone can help me out with this question, thanks alot
 
Old 07-19-2003, 11:11 AM   #5
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 59
well just for that particular example you could do:
ls ???[0-2]
 
Old 09-01-2004, 10:53 PM   #6
subaruwrx
Member
 
Registered: Mar 2004
Distribution: Ubuntu Feisty
Posts: 641

Rep: Reputation: 30
Quote:
Originally posted by lido
Hi,

I have a question which I'm not sure if my ans is right.

For example if a directory contains the following files, what's the command to list the files ending with a number less than 3 and the command to list the files ending with any single digit number.

The files as follows
abc1
abc2
abc3
abc11

My ans for the question is ls *[0-2], but it list the file abc11 as well. Is there any more specific command to both the questions shown above?


Thanks you very much
How about

Code:
ls *[0-2]{1}
 
Old 09-02-2004, 11:35 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Actually, the asterisk '*' symbol is just one of many used by various regex engines. It generally denotes zero or more chars at that position in the regex.
If you want to know more, try
man 7 regex
or
http://regex.info , the wbsite devoted to Mastering Regular Expressions by Jeffrey Friedl, generally acknowledged to be the definitive book. There's a full searchable index link on the front page.
 
  


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
Need help with regular expression aecaudel Programming 6 11-04-2005 06:28 AM
Wildcard Entry and Regular Entries in DNS mr_fern Linux - Networking 0 08-06-2005 09:30 AM
Anyone know regular expression? ahhua Linux - Software 1 12-04-2003 09:13 AM
Regular Expression slizadel Programming 4 07-28-2003 06:16 AM
regular expression gumby Programming 3 07-15-2003 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:44 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