Live data from Hacker News

Learn Regex The Hard Way

regex.learncodethehardway.org

61–64 of 64 posts

Re: Learn Regex The Hard Way

#61
post #46

Earlier quoted context omitted.

the solution seems pretty easy. simply leave out the beginning/end-of-line assertions. [0-9]+|[A-Z]+ would suffice for that example. i agree that introducing capture groups IS too early, but you can add the parentheses without mentioning capture groups, even if they do capture. grouping still has great value as a precedence indicator which is taught in gradeschool arithmetic. it's rather unfortunate that the syntax t…

Yes, I hate that (?:) syntax. Who the hell thought that crap up. But, I will point out that you attributed the error to NL/EOL assertion, when actually it was order of precedence of | being greater than $ and ^. It's a simple nearly 1-2 character mistake, not a "novice" mistake that discredits the entire book.

yeah i apologize, perhaps i was a bit harsh. i did understand what the issue was and never claimed that it was the newline/EOL assertion itself. i said that your newline/EOL assertion is being treated as PART of the alteration, which is exactly what happens - yes because of pipe's higher operator precedence when no explicit grouping is defined.

novice or not though, 2 misplaced chars in a regex can make the diff between a security feature and a security hole, in this case matching a plethora of inject-able, potentially malicious characters which appear nowhere in the regex, not even as a wildcard ".", i would never make the claim that a 2-char mistake which matches this far beyond its intent is a minor oversight in a real-world, public facing application - and isn't that the ultimate goal?

the only issue in the context of a book for a regex beginner is that the regex gives the appearance of newline/EOL assertion hugging an alteration, but does something quite different. removing those assertions would clear things up for the better.

Re: Learn Regex The Hard Way

#62
post #30

The regex shell is a neat idea. In many situations I'd like to generate strings accepted by the regex, to check that my regex is tight enough. I know this is hard in general (for lots of reasons, basically all reducing to "there are a lot of strings and no easy way to iterate through them in a satisfying way"). But, has anyone made any progress on this for the "easy" cases?

Your wish has been granted: http://txt2re.com/ I use this all the time. No wonder I don't know to hand write a Regex.

That's a neat page, which does help construction of regex's.

But, it does not address the question I posed.

The regex R generates a language L of strings accepted by R. I want a facility for generating example elements of L.

Given that L often is infinite or has immense cardinality, this is hard to do. I think I want a breadth-first descent of the tokens in the regex, but it's not always that simple.

Re: Learn Regex The Hard Way

#63
post #57
post #7

Earlier quoted context omitted.

I'm not a CS graduate. I first learned of state machine from an article posted here on HN a few months ago. I learned regular expression from the regular-expression.info site and from the first 4 chapters of Jeffrey Friedl's book over 5 years ago. I don't recall an introduction to NFA/DFA from them either. I'm pretty comfortable with regex and use them regularly (no pun intended) and so far, I don't feel that I've mi…

Chapter 4 of Jeffrey Friedl's "Mastering Regular Expressions" goes in depth about NFA/POSIX NFA/DFA. It even has car analogies!

It must have been the 3 first chapters then. At the time, they were enough for me to understand and "get going" with regex. Various other online resources have filled little gaps here and there over time. This thread makes me want to revisit the book and resume my reading of the next 3 chapters, a long overdue promise to myself. I'm glad that the book will cover the topic of FA then.

Re: Learn Regex The Hard Way

#64
post #21

Earlier quoted context omitted.

My 13 year old son is working through Learn Python the Hard way. He likes it a lot and is building things that interest him. He will spend the whole day fiddling with Python working on a text based choose your own adventure game that one of the chapters had him build. He's approached programming a couple of times before, but LPTHW is the first time he's really stuck with it. In that regard, I think Zed is doing an aw…

That's awesome. It's funny because I didn't even try to write the book for kids, but happy it seems to work well for them.

Kids tend to be, in general, kinda like adults in a lot of ways. Whodathunk? :-)
Post reply on HN