What is the difference between Regular Expressions and Globbing?
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
* -- Any amount of any characters, or nothing at all
? -- One of any character
[abc] -- Just one of the characters "a", "b", or "c".
[^abc] -- Any one character except "a", "b", or "c".
For example, do you understand that in globbing "*" means "zero or more of any characters" and in regexes it means "zero or more of the preceding character"?
Also, in regular expressions you have "+", which matches the preceding character one or more times, and "?", that matches it zero or one times.
Extended regualar expressions also have "{}". For example:
Code:
a{3, 6}
Matches anywhere from 3 to 6 "a"s in a row. Also, you can leave out any of the two numbers (but still leave in the comma) if you only want an upper or lower limit.
There are much more features in regular expressions, but you Google for "regualar expression tutorial" for that .
"globbing" is an alternative name for "filename expansion" in bash (and other shells but let's keep this simple). During filename expansion, bash substitutes a pattern such as *.jpg with the names of any files matching the pattern.
Regular expressions are also patterns which can be used to match things. For historical reasons, not all programs using regular expressions use identical regular expressions. The different regular expressions use similar ideas but differ in detail and power.
Bash pattern matching is essentially just another variety of regular expression. Historically it was one of the simplest regular expressions for ease of typing (for example it uses * to mean "any number of any character" while all the others use .*).
If you want to learn regular expressions, sooner or later you'll come across the SED command. Here's an excellent tutorial: http://www.grymoire.com/Unix/Sed.html
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.