Regex Prefix Optimizer
Consolidate a list of strings into a compact regex by sharing common prefixes
Consolidate a list of strings into a compact regex by sharing common prefixes
/colo(?:rs?|urs?)/Naive alternation — (color|colour|colors|colours)— works correctly but it's wasteful. The regex engine has to try each branch in turn, and the pattern itself is longer than it needs to be. By building a trie from the input strings and walking it in two passes, this tool produces equivalent regexes that are both shorter and faster to match.
color/colour become colou?rbecause the trie's "u" branch is optional from the "o" node.colors/colours turns the result into colou?rs? in one stroke — both endings collapse into the same trailing ?.cat, bat, hat collapses to [bch]at instead of (?:b|c|h)at.(?:...)so it doesn't pollute capture group indices.The most common use case is converting a curated wordlist (URL slugs, blocked phrases, file extensions, error codes) into a single match expression for filtering or routing. It also makes generated regexes from build tools much easier to read when something goes wrong.