
Your Java Regex Just Silently Broke in Production. Here's How to Make That Impossible.
A colleague pushes a fix for a validation bug. The regex looks right. Tests pass. Two weeks later, a user reports that their perfectly valid email address is being rejected — because the fix introduced an unbalanced bracket that the compiler never complained about. This is the nature of raw regex in Java. The compiler has no opinion. The mistake lives quietly in a string literal until runtime hands you the bill. I built Sift to make this class of bug unrepresentable. What Sift actually does Sift is a fluent DSL for building regular expressions in Java. Its core idea is simple: instead of writing a string, you traverse a type-state machine . Each method returns only the next valid state — so wrong transitions don't exist as methods, and the compiler rejects incomplete or structurally invalid patterns before your code ever runs. The before/after speaks for itself: // Before — what does this even do? Pattern p = Pattern . compile ( "^(?=[\\p{Lu}])[\\p{L}\\p{Nd}_]{3,15}+[0-9]?$" ); // Afte
Continue reading on Dev.to
Opens in a new tab



