Re:Show HN: Improve your Python regex skills with 75 interac...
by mci on Tuesday November 30, 2021 @08:25AM
(#29391820)
I like it! Here is a gotcha my students stumble on. I have not noticed it while skimming your book: ^ and $ do not have special priorities. To match alternatives, write ^(abc|def)$, not ^abc|def$
[ Parent
| on HN ]
Re:Show HN: Improve your Python regex skills with 75 interac...
by asicsp on Tuesday November 30, 2021 @08:56AM
(#29392096)
Yeah, that's a good case to be aware of.
I do mention it in the book while discussing anchors (indicating alternatives have their own independent anchors) [0] and grouping [1].
I also discuss how `re.fullmatch` is useful, especially when constructing an alternation pattern from a list of terms. Easier to use fullmatch instead of manually adding a group and string anchors.
[0] https://learnbyexample.github.io/py_regular_expressions/alte...
[1] https://learnbyexample.github.io/py_regular_expressions/alte...
Re:Show HN: Improve your Python regex skills with 75 interac...
by staticautomatic on Tuesday November 30, 2021 @12:17PM
(#29394584)
Without the group, does this match abc at the start or def at the end?