Make repetition earn its keep
Choose bounded, greedy, or lazy quantifiers based on the delimiter and failure mode of the text.
The move: treat every repeat as a design choice. The dangerous quantifier is not always the longest one. The dangerous quantifier is the one whose job is undefined. If you write .*, the engine hears "any character, any count." That may be fine in a tiny, controlled string. It is usually too vague in logs, HTML, CSV, and user input. Use the PDCA loop. Plan the delimiter and the maximum plausible length. Do the smallest pattern that expresses that plan. Check it against the happy path, the missing delimiter, the extra delimiter, and the too-long input. Act by tightening the…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in