LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What is the difference between Regular Expressions and Globbing? (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-difference-between-regular-expressions-and-globbing-828589/)

Linux.Girl 08-26-2010 06:41 AM

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

MTK358 08-26-2010 07:00 AM

Globbing:

Code:

* -- 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".

Regular Expressions:

http://en.wikipedia.org/wiki/Regular_expression

Linux.Girl 08-26-2010 07:20 AM

Thanks but I still don't understand the difference, they look the same to me...

MTK358 08-26-2010 07:23 AM

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"?

Linux.Girl 08-26-2010 07:27 AM

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!

MTK358 08-26-2010 07:32 AM

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 :).

Linux.Girl 08-26-2010 07:48 AM

ok, thanks, I will search for tutorials :-)

catkin 08-26-2010 07:20 PM

"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 .*).

Linux.Girl 08-27-2010 05:34 AM

very very clear, great explanation! thanks, really!

sycamorex 08-27-2010 06:40 AM

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.