LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Reply
 
Search this Thread
Old 08-26-2010, 07:41 AM   #1
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 42

Rep: Reputation: 2
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
 
Old 08-26-2010, 08:00 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
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
 
Old 08-26-2010, 08:20 AM   #3
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 42

Original Poster
Rep: Reputation: 2
Thanks but I still don't understand the difference, they look the same to me...
 
Old 08-26-2010, 08:23 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
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"?
 
Old 08-26-2010, 08:27 AM   #5
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 42

Original Poster
Rep: Reputation: 2
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!
 
Old 08-26-2010, 08:32 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
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 .
 
1 members found this post helpful.
Old 08-26-2010, 08:48 AM   #7
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 42

Original Poster
Rep: Reputation: 2
ok, thanks, I will search for tutorials :-)
 
Old 08-26-2010, 08:20 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
"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 .*).
 
1 members found this post helpful.
Old 08-27-2010, 06:34 AM   #9
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 42

Original Poster
Rep: Reputation: 2
very very clear, great explanation! thanks, really!
 
Old 08-27-2010, 07:40 AM   #10
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,578
Blog Entries: 1

Rep: Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027Reputation: 1027
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
 
1 members found this post helpful.
  


Reply

Tags
globbing, regex


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expressions Wim Sturkenboom Programming 10 11-19-2009 02:21 AM
help with regular expressions mariogarcia Linux - Software 3 01-28-2009 04:23 AM
Regular expressions bhuwan Programming 5 02-26-2006 12:07 AM
help with REGULAR EXPRESSIONS ner Linux - General 23 11-01-2003 12:09 AM
regular expressions? alaios Linux - General 2 06-11-2003 04:51 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration