Learn Regex The Hard Way
regex.learncodethehardway.org
regex.learncodethehardway.org
Then it occurred to me that plenty of people have probably written libraries to do exactly that, but nobody uses them because we all already have regexes built-in almost everywhere that we want to use them. Hell, I've never even looked for one, even though I choke back a little vomit every time I introduce a new regex into a codebase because of how much future debugging pain I know they can cause (all but the shortest ones force what's essentially a full context-shift in order to parse, and in reality what usually happens is people scan a regex as one chunk and say "Eh, a regex, it's probably right, hopefully my bug is somewhere else..." until they have some concrete reason to think otherwise).
Sort of a shame, really, that such a problematically condensed syntax won the prize so early on, and now even those of us that hate it are too comfortable with it to look for something better.
It's my belief (totally unfounded) that learning a simple symbolic language like regular expressions teaches you how to handle other symbolic languages like mathematics, chemistry, and programming. That's one of the reasons I'm teaching it and trying to get other people to use it.
More importantly though, they are damn handy. As long as you don't abuse them in places where a lexer+parser is better, you can get a lot done with very little regex in very short time.
Larry Wall’s writings on this general topic are fairly convincing. http://www.perl.com/pub/2002/06/04/apo5.html?page=2
I couldn't agree more. because of lack of the "language" approach to them, their weird syntax, and the fact that the "verbose" mode for their definition is almost unknown, they come out as a sort of voodoo that only gurus can handle. Moreover, this results in tons of broken code in production. They're simple, beautiful and handy, but have an unfortunate historical load.
var regex1 = /some_regex/,
regex2 = /other_regex/;
var regex3 = alternative(regex1, regex2);
var regex4 = kleene_star( sequence(regex1, regex2) );Also lots of engines have the verbose form, problem is there's been too many Perl hackers writing those god awful huge regex so everyone thinks dense and succinct is the only way to write regex.
Also, I think word problems develop an essential skill, namely mapping new problems (described usually in natural language) to mathematical concepts using the symbols. Problems come first, the neat symbolic form comes way after and generally the main problem is mapping a vague problem description to a concrete description using the symbolic language provided by mathematical notation.
Agreed O'Reilly is probably more famous for their "completeness" rather than effectiveness at teaching.
https://news.ycombinator.com/item?id=3297996
Even considering the fact that alteration is introduced after the needed concepts of NL and EOL assertions in "Exercise 7: The Beginning And End"
no me gusta :(
you are wrong, however, not to mention this alongside examples that specifically display this in an unrelated context, as this is something that is far from obvious. you can
1. easily use different examples or
2. add one line of text that clears this up
on the other hand, the title of the book is to learn regex the hard way, so i'm quite possibly the one who is wrong here. i am not trying to troll, trust me, i respect the work and knowledge you have put into this. but as someone who has been confused by this in the past during my own learning, i see no reason why you think i'm an exception and continue to argue against any clarification or change.
1. "I have been bit in the past by not knowing an obscure fact." 2. "To protect myself, I must learn every obscure fact to prevent this from happening again." 3. "This here has a missing obscure fact and is therefore going to hurt me and everyone around me."
This attitude that you have to teach someone everything about something right away is the reason most educational tech books suck. You do not need to teach someone everything right away. You don't even need to teach them everything as long as what you've taught is the foundational elements and those are correct.
This attitude is also hyperbolic. The book is not going to destroy the world because you have a problem with one small portion of one exercise that you can't even fix yourself.
Finally, you keep saying these things, and you keep asserting you're correct, but I don't see a solution from you. It's in a git repository:
http://gitorious.org/learn-regex-the-hard-way/
So put your money where your mouth is and send me a patch. If it's soooooo easy to fix and explain then prove me wrong.
Until you offer up your supposedly superior world saving solution I have to assume you're just wrong but can't admit it.
i would be more than happy to send a patch if i wasn't 100% sure that it would be rejected or ignored on the stated grounds. these convos along with the only 2 outstanding, uncommented, unmerged, 3.5-month-old merge requests have not exactly instilled a great vote of confidence that you are open to taking people's code or advice.
i will leave you with this - after reading through your alteration section (and perhaps the whole book), beginning regex students will be unable to correctly answer the following question (using your own example) which appears not to use any concepts not previously discussed:
Circle all strings below which will be matched by ^[0-9]+|[a-z]+$
a. abc
b. 123
c. abc123
d. 123abc
e. abc_45&{`!123
f. 123_xk&{`!abc
g. _xk&{`!abc
h. 123_xk&{`!
if you believe this is some edge-case gotcha and as a teacher, you're okay with this, that's fine with me, i've spent an order of magnitude more energy than i should have trying to help.
By the way, from a quick glance, I believe there is no chapter devoted to discuss how the regexp engines work (which is ok) but will there be a section on "when things explode in your face due to exponential behaviour"?
I remember when I first noticed a regex I wrote had a bewhaviour like that and it was kind of enlightening, because earlier I had always assumed all the talk about this things was rather academic :)