LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 06:41 AM   #1
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 53

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

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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, 07:20 AM   #3
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 53

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

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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, 07:27 AM   #5
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 53

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, 07:32 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
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, 07:48 AM   #7
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 53

Original Poster
Rep: Reputation: 2
ok, thanks, I will search for tutorials :-)
 
Old 08-26-2010, 07:20 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
"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, 05:34 AM   #9
Linux.Girl
Member
 
Registered: Aug 2010
Posts: 53

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

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
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



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 01:21 AM
help with regular expressions mariogarcia Linux - Software 3 01-28-2009 03:23 AM
Regular expressions bhuwan Programming 5 02-25-2006 11:07 PM
help with REGULAR EXPRESSIONS ner Linux - General 23 10-31-2003 11:09 PM
regular expressions? alaios Linux - General 2 06-11-2003 03:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:55 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration