What is the difference between Regular Expressions and Globbing?
Hello everyone,
As the subject says, can anyone explain to me what is the difference between Regular Expressions and Globbing? Thanks in advance. Linux.Girl |
Globbing:
Code:
* -- Any amount of any characters, or nothing at all http://en.wikipedia.org/wiki/Regular_expression |
Thanks but I still don't understand the difference, they look the same to me...
|
The differences are huge, actually.
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"? |
No, I didn't know that, I am a newbie and don't know the differences, that's why I was asking, sorry if it sounded lame :-)
Thanks! |
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} There are much more features in regular expressions, but you Google for "regualar expression tutorial" for that :). |
ok, thanks, I will search for tutorials :-)
|
"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 .*). |
very very clear, great explanation! thanks, really!
|
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
|
All times are GMT -5. The time now is 09:28 AM. |