ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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]/'
No. There is plenty of information and tutorials, so there's no reason to waste your money on a book. You could read "man perlre" and still learn a lot.
Quote:
Originally Posted by davejjj
Example problem: use Linux sed or tr to capitalize the first word of a string. Gosh that sounds easy!
You could use google search, you know. Try sed capitalize
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.
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
Understand that there are two general forms for regular expressions. The older of the two is largely considered deprecated, though it still sees use and continues to be supported for backward compatibility.
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:
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.
But yeah, in the end it just comes down to practice and experience. It takes time to learn anything complex, and regex is certainly complex. Just keep at it.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.