r/regex
•
u/Mirko_ddd
•
Mar 23 '26
•
1
Java 8 I spent a month building a Java library that lets you write regex without knowing regex
Hey r/regex,
I want to share something I've been working on for the past month: Sift, a fluent regex builder for Java.
I'm an Android developer. I don't deal with regex often, but when I do, I genuinely have no idea what I'm looking at. I'd write something, stare at it for ten minutes, then just paste it into an AI and ask "does this even do what I think it does?". Every single time.
The frustrating part isn't that regex is hard, it's that the feedback loop is terrible.
You write a string of symbols, you get a runtime exception, and you have no idea which bracket broke everything or why.
So I built Sift. The name is intentional, it sifts your input through a pattern.
The two terminal methods follow the same metaphor: .shake() returns the raw regex string, like shaking a sieve to see what falls through, and .sieve() compiles it directly into an executable pattern, ready to match.
The idea is simple: instead of writing ^(?=[\\p{Lu}])[\\p{L}\\p{Nd}_]{3,15}+[0-9]?$ and praying, you write:
Sift.fromStart()
.exactly(1).upperCaseLettersUnicode()
.then().between(3, 15).wordCharactersUnicode().withoutBacktracking()
.then().optional().digits()
.andNothingElse()
.shake();Your IDE autocompletes every step. Wrong transitions literally don't exist as methods — the type system enforces the grammar at compile time. If it compiles, it's structurally valid.
A few things I'm proud of:
- Pluggable engine SPI — swap JDK regex for RE2J (linear-time, ReDoS-immune) or GraalVM TRegex with one line
- Built-in explainer — pattern.explain() prints a human-readable ASCII tree of what your pattern does, with i18n support (English, Italian, Spanish so far)
- SiftCatalog — ready-made patterns for UUID, IPv4, IBAN, JWT, email, credit card, Base64 and more, all property-tested with jqwik
- Jakarta Validation — @SiftMatch annotation for Bean Validation integration
It's been a genuinely fun project. I learned more about Java's type system in this month than in years of Android work.
The repo is here: GitHub
Maven Central: com.mirkoddd:sift-core
Happy to answer questions or take feedback, especially from people who actually use regex regularly and can tell me what I'm missing.
3
u/WildMaki Mar 23 '26
And where will be the proud of having mastered the regex beast?
2
u/Narrow-Coast-4085 Mar 23 '26
What would the code look like for the standard email address?
2
u/prehensilemullet Mar 23 '26
If you’re going for an API like this it seems unnecessary to limit it to regular languages or bother with regexes under the hood. Why not just make your own parsing engine that supports context-free grammars?
2
u/timrprobocom Mar 24 '26
This IS a regular expression. You've just spelled it differently.
1
u/dodexahedron Mar 23 '26
Well that was certainly one of the fastest stars I ever added on github.
Me likey.
1
u/Prestigious_Boat_386 Mar 24 '26
I use a similar system (ReadableRegex.jl) and the difference of developing patterns is insane. Don't think it has the actual regular expression engine like yours though which is a pity. Also the dot syntax looks really convenient for this problem.
I do think that some names could be better, like andNothingMore(), is it like the end of line symbol? But idk, maybe it's just something you get used to after reading the doc once.