Quote:
Originally Posted by
Straitsfan
So when would you glob and when would you use regular expressions? I'm still somewhat confused.
Most of the time you won't have the option to choose between using glob or regular expressions, and will have to use what the tool offers. As a general rule of thumb you will be using glob for the shell prompt, and regex for everything else.
For example if from a shell prompt you type
ls p* you would expect the shell to expand p* to any file begining with p (glob) not any file with zero or more p's anywhere in the name (regex). Which highlights another difference in glob (patterns span the whole string, like having an implied "^" at the front and "$" at the end with regex).
Here is a little table with glob and regex
equivalent
glob | regex |
b | ^b$ |
b* | ^b.*$ |
*.jpg | ^.*\.jpg$ |
[ab]* | ^[ab].*$ |