LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-05-2009, 02:16 PM   #1
yanghwanim
LQ Newbie
 
Registered: Mar 2009
Location: Honolulu, Hawaii
Distribution: CentOS/Fedora/Ubuntu/RedHat
Posts: 18

Rep: Reputation: 0
Talking Best way to learn Regex's


Why is learning Regex's so hard? Can you direct me to the best, and most efficient way to learn Regex's without stabbing myself in the eye with a pencil!!!

Last edited by yanghwanim; 06-05-2009 at 03:30 PM.
 
Old 06-05-2009, 02:42 PM   #2
sl33p
Member
 
Registered: Dec 2008
Location: Tahiti
Distribution: Kali Linux
Posts: 42

Rep: Reputation: 17
Hi yanghwanim,

A good start:

Code:
$ man 7 regex
Regards,
 
Old 06-05-2009, 03:42 PM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
You mean regular expressions ? Try here:
http://www.regular-expressions.info/
or a shorter one:
http://www.grymoire.com/Unix/Regular.html
 
Old 06-05-2009, 06:12 PM   #4
chuckbuhler
Member
 
Registered: Oct 2005
Distribution: SuSe
Posts: 95

Rep: Reputation: 17
O'riley's RegEx book, vim to create test files, and grep to play with them. And a bit of time to try, test, and practice.

The copy of the book that I have is falling apart, but I've never read the thing cover to cover. I find something that I'd like to be able to do, use the book as a reference, then try out what I've read. I use a lot of regex's in the spam filter on our mail system at work, so I use them a lot, but when there's one that's a little tricky, I still create a test file and play with grep. It may not be the fastest way to learn, but I figure that by the time I retire in 10 years or so, I may not need the book anymore!
 
Old 06-05-2009, 06:47 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529Reputation: 3529
http://txt2regex.sf.net might be nice to play with as well.
 
Old 06-05-2009, 07:47 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by yanghwanim View Post
Why is learning Regex's so hard?
to someone who is starting out, its normal. however, basic string manipulation doesn't really need to involve regular expressions that much if you choice of tools/languages used provides you excellent string manipulation capabilities/functions.
 
Old 06-06-2009, 08:25 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by yanghwanim View Post
Why is learning Regex's so hard?
It's not---all you have to do is:
  • Remember a bunch of characters that have a special meaning in certain contexts---and then remember which ones have different special meanings in different utilities.
  • Learn how to use the "\" (escape) character to change the meaning of a character from special to literal (or vice-versa) depending on context.
  • Learn about extended Regexes which add more special characters, and which may or may not require the use of of even more special characters to tell the program whether the characters are special.....depending on context.
  • Learn all about quoting and why a double-quote is weaker than a single, and how to flip between strong and weak coding, and how to quote a quote.
  • AND---how some programs allow you to change what is special on the fly.

Ummmmm, maybe it IS hard.........
 
Old 06-06-2009, 08:36 AM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
Well, just for your info, I never learned regex ... and probably never will, for the reasons pixellany has laid out. I just look at the sites I gave and go from there. I don't use it all that often anyway.
 
Old 06-06-2009, 09:17 AM   #9
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,811
Blog Entries: 1

Rep: Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191Reputation: 1191
As pixellany pointed it out, there's not THAT much to learn - it becomes tricky when you need to apply the knowledge to a wide range of scenarios.
 
Old 06-06-2009, 09:28 AM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by sycamorex View Post
As pixellany pointed it out, there's not THAT much to learn - it becomes tricky when you need to apply the knowledge to a wide range of scenarios.
You are so much more concise than I am......
 
Old 06-08-2009, 09:19 PM   #11
yanghwanim
LQ Newbie
 
Registered: Mar 2009
Location: Honolulu, Hawaii
Distribution: CentOS/Fedora/Ubuntu/RedHat
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pixellany View Post
You are so much more concise than I am......
You just scared me....lol.....
 
Old 06-08-2009, 09:49 PM   #12
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,834

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
I like to keep an eye on regex threads - even if I don't (or can't) answer.
Some of the answers are amazing ... great learning tool to try and figure them (the answers !!!) out sometimes
 
Old 06-08-2009, 11:12 PM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
It's all about puzzles.....

In my youth, I was a big fan of Martin Gardner and "mathematical games" in Scientific American. Regexes are just another puzzle....
 
Old 06-09-2009, 01:09 AM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
There are some good links above; the book Mastering Regular Expressions http://regex.info/ is definitely very good.
As well as showing the basics, it also shows that different langs/tools use different 'regex engines', so the syntax for one tool may not do the same thing (or anything) in another tool.

Last edited by chrism01; 06-09-2009 at 01:11 AM.
 
  


Reply


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
help :() How to find an address using "grep" & regEx's. linuxmaveric Programming 8 04-28-2010 01:31 AM
How to learn c++? jmite Linux - General 10 10-03-2008 06:19 PM
sed: howto group regex's into AND/OR clauses? jhwilliams Linux - Software 5 08-01-2007 03:19 PM
Matching values in a bash script grep, regex's ... ? maxvonseibold Linux - General 6 01-29-2007 07:07 AM
Need a regex, I suck at regex's d3funct Programming 4 02-25-2002 09:28 PM


All times are GMT -5. The time now is 02:47 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration