3 Pitfalls and sand in the gears
As compact and expressive as regular expressions can be, there are times when they simply go disastrously wrong. Be careful to avoid pitfalls, and at least understand and identify where such difficulties arise.
Puzzle 6 Catastrophic backtracking
Summary Use regular expressions to validate a message protocol quickly.
In this puzzle, we imagine a certain message protocol (as we do in many of the other puzzles). We have a message alphabet that consists of the following symbols:
Codepoint |
Name |
Appearance |
---|---|---|
U+25A0 |
Black Square |
■ |
U+25AA |
Black Small Square |
▪ |
U+25CB |
White Circle |
○ |
U+25C9 |
Fisheye |
◉ |
U+25A1 |
White Square |
□ |
U+25AB |
White Small Square |
▫ |
U+25B2 ... |
Get Regular Expression Puzzles and AI Coding Assistants now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.