4 ms·
Cute quiz. Question 9 is incorrect, however – or at least poorly worded. It asks about regex matches and only considers the last one to match, while the second
by StefanKarpinski 9y ago
Cute quiz. Question 9 is incorrect, however – or at least poorly worded. It asks about regex matches and only considers the last one to match, while the second one also matches, albeit incompletely. The last regex is the only one that matches the entire input string, but that's not usually how regexes work – e.g. in Perl or Ruby. This verbiage seems to be specific to Python, which uses `re.match(str)` to mean "match the entire string" as compared to `re.search(str)` which means "search for any matching substring". Arguably a decent distinction, but very Python-specific.
[Update: this is now fixed in the quiz.]
- tobyhinloopen 9y agoThe given regular expression does not match `blabber`, it matches `blabbe` (minus the `r`). I got that one wrong as well. The question should have been "which regular expression FULLY MATCHES X and not Y"
- StavrosK 9y agoNope: In [3]: re.search("b[l].*e", "blabber") Out[3]: <_sre.SRE_Match at 0x7f2db79ed030> "Matches" means "matches". If they wanted "fully matches", they should have specified "^$". That's why anchors exist.
- tobyhinloopen 9y agoYes, I agree. I just explained where it went wrong and that "Match" can mean multiple things. It matches `blabber`, but the match result is `blabbe`.
- deleted 9y ago[deleted]
- Bartweiss 9y agoThanks, I had to check the Python docs to be sure I wasn't crazy! I went A->D, stopped at B because it 'worked', and got it wrong. D also works, obviously, but I'm glad the question is cleaned up now.