Learning RegEx? Regular Expressions
I have looked at a number of online tutorials but I am becoming convinced that I will need to buy a book on regex to ever understand it. Isn't this really the only way to learn it? Opinions? Thanks.
Example problem: use Linux sed or tr to capitalize the first word of a string. Gosh that sounds easy! Probably just sed 's/^./[A-Z]/' or maybe sed 's/^[a-z]/[A-Z]/' |
Quote:
Quote:
Quote:
|
Of course a book isn't the only way to learn regex. What really makes you learn is practice and a good tutorial, apart from frequent use of "info sed" for help on sed regexes, and "man 7 regex" for info on POSIX regexes.
BTW, in the info page for sed I find a page linked: http://sed.sourceforge.net/grabbag And google for "sed one liners", it's a very well known doc with the more common sed tasks. There's also the annotated version: "sed one liners explained". |
Start with the regex manpage. It will be your starting point and reference as you study regular expressions.
Code:
man 7 regex Further understand that every program which accepts regular expressions has its own rules. You must consult the program's documentation to understand its regular expression syntax. For tutorials, I recommend reading at least two of the following: http://www.scootersoftware.com/RegEx.html http://www.grymoire.com/Unix/Regular.html http://www.regular-expressions.info/ http://www.ibm.com/developerworks/ai...ps3/index.html http://www.ibm.com/developerworks/li...3-7/index.html HTH |
Note that it's not just about learning regex, it's also about learning sed and the other tools. I learned quite a bit from the sedfaq, including how to capitalize a string.
http://sed.sourceforge.net/sedfaq.html Code:
$ echo "david" | sed 's/.*/\u&/' |
And while "all the info" is out there and comprehensive, it's not always
easy to understand. I find no harm in buying a book, and happily recommend Jeffrey Friedel's "Mastering regular expressions", which is not only very accurate and exhaustive on the subject, but also actually fun to read. Cheers, Tink |
All times are GMT -5. The time now is 06:46 PM. |