LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   wildcard vs regular expression (https://www.linuxquestions.org/questions/linux-newbie-8/wildcard-vs-regular-expression-74014/)

lido 07-19-2003 12:37 AM

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

Tinkster 07-19-2003 01:12 AM

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

lido 07-19-2003 01:31 AM

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

lido 07-19-2003 09:55 AM

Hi,

Does anyone have any idea how it can be done?

Apprecite if someone can help me out with this question, thanks alot

DrOzz 07-19-2003 10:11 AM

well just for that particular example you could do:
ls ???[0-2]

subaruwrx 09-01-2004 09:53 PM

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}

chrism01 09-02-2004 10:35 AM

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.


All times are GMT -5. The time now is 02:22 PM.