NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io, #453 most downloaded on crates.io
An implementation of regexes, supporting a relatively rich set of features, including backreferences and look-around. Aims to be compatible with Oniguruma syntax when the relevant flag is set.
Latest stable
0.20.2
Last release 11 days ago
11 Nov 2026
Release timing varies
gaps range from 2 weeks to 10 months
Nearly every release is documented
notes for 33 of 33 stable releases
Nothing withdrawn
no release was ever pulled
10 years old
33 releases · first in 2017
Drag across the ruler to compare, or tap a release to open it.
Fixed more cases where the optimizations made were unsound
A new Expr::has_descendant_or_self method to easily traverse the Expr descendants to find an Expr matching a predicate.
Expr::has_descendant_or_self method to easily traverse the Expr descendants to find an Expr matching a predicate. (#319)RegexOptionsBuilder::optimize / RegexBuilder::optimize flag to disable the expression-tree optimization pass (enabled by default), and rework it into two tiers: optimize() now takes an OptimizeOptions struct with a find_not_empty flag that skips only the KeepOut (\K) and trailing-lookahead rewrites, while the safe rewrites still apply — so find_not_empty patterns benefit from them instead of skipping the whole pass. The decision on whether to optimize is centralized on RegexOptions::should_optimize and forwarded to the prefilter helpers (start_bytes, required_bytes) so they analyze the same tree as the compile path. (#323)\cX and \C-X in Oniguruma mode, e.g. \ca matches \x01 and \c\\ matches \x1C, both inside and outside of character classes. Without Oniguruma mode they are still invalid escapes. (#320)(?=x|(x))\1x no longer matches xx. (#313)(b*)(?<!\1)c matching abc, or hit the backtrack limit when a pattern had two such lookbehinds, like (a*)b(?<=\1b)(c*)d(?<=\2d). (#314)(?:a|(?=b)){2,}) could stop before reaching the minimum when it ran again at a position its previous run had reached, for example inside a repeated lookahead: (?:(?=(?:a|(?=b)){2,})a){2} matched aa. (#312){n,} repetition whose body can match an empty string ended as soon as an iteration matched empty, even below the minimum. When the first iteration matched empty, the last required one now still runs, so (?:(?=^)a*){2,}b matches aab. A body that reads a capture group it sets itself can match differently in the next iteration, so there all required iterations run, and ^(?:(?(1)a|())){3,}$ no longer matches an empty string. (#325)(z)?(?>a*(?(1)x))a matched "aaa". (#316)(?(1)(?:a|b)), was parsed as (?(1)a|b), so b became the false branch. (#315)(a(?i)b)c, now end with the group. Before, they leaked to the rest of the pattern, so (a(?i)b)c matched aBC and (?x)G(o(?-x)o) g did not ignore the spaces after the group. Only (?:...) and (?flags:...) restored them. (#317){,} is now literal text, as in Oniguruma, instead of being parsed as {0,}. For example (?:ab){,} matches ab{,}. {,n} is still {0,n}, and without Oniguruma mode {,} is unchanged. (#321)? after an interval with swapped limits, like a{3,2}?, is now another quantifier, as in Oniguruma, so it makes the possessive a{2,3} optional. Before, it made the repeat lazy, so a{3,2}? matched aa in aaa and didn't match an empty string. A ?, * or + after a repeated empty group, like in (?:)** or (?:){3,2}?, is now dropped along with it instead of failing to parse. (#322)? after a fixed interval, like a{3}?, is now another quantifier, as in Oniguruma, so a{3}? means (?:a{3})?. Before, it made the repeat lazy, which doesn't change anything for a fixed count, so a{3}? didn't match aa and a{3}?? matched aaa instead of an empty string. a{3,3}? is still lazy, and without Oniguruma mode a{3}? is unchanged.(?:(\1|a)b){2} panicked on abab and ^((?(1)b|a))$ matched b but not a. (#328)Your coding agent can read these notes before it upgrades. Set up the MCP server →
Add RegexOptionsBuilder::build_delegate_prefilter to disable building the prefilter
RegexOptionsBuilder::build_delegate_prefilter to disable building the prefilter (#282)RegexOptionsBuilder::start_bytes that returns the first bytes that can match a pattern so you can build your own prefilter (#282)RegexOptionsBuilder::required_bytes that returns the required bytes for a pattern to match (#287)RegexOptionsBuilder::max_prog_size / RegexBuilder::max_prog_size to cap the number of VM instructions emitted while compiling. Subroutine calls are inlined at compile time, so a self- or mutually-recursive pattern can expand without bound even while the recursion-depth cap is respected; this bounds the emitted instruction vector instead. Exceeding the cap returns CompileError::PatternTooComplex. Disabled by default. (#298)delegate_size_limit and delegate_dfa_size_limit. (#286, #309)RegexOptionsBuilder::delegate_dfa_skip_cache_capacity_check / RegexBuilder::delegate_dfa_skip_cache_capacity_check, enabled by default. Setting it to false makes the reverse DFA of a variable-length lookbehind strictly honour delegate_dfa_size_limit, so a too-small limit becomes a compile error. (#309)ByteSet::is_subset to test whether one byte set is a subset of another. (#289)\b, \B, \<, \>) are no longer marked hard outside a lookbehind. regex-automata supports them, so a pattern like \b(?:foo|bar|baz)\b now compiles to a single delegated engine instead of one branch per alternative — previously it grew linearly with the number of alternatives. They remain hard inside a lookbehind, since regex-automata's reverse DFA can't run a variable-length lookbehind on unicode haystacks. The half-boundary variants (\<, \>) and \Z are still always hard. (#311)Regex::capture_names reports the name for each of them, and named backrefs resolve to the last group with that name (#177)delegate_dfa_size_limit (or the default of 2 MiB); for example (?<=\p{L}{99,100})x failed to compile with default settings. The capacity is now rounded up to the minimum required. Ordinary delegates were not affected because the meta engine falls back to another engine when the lazy DFA cannot be built. (#309)delegate_dfa_size_limit now sets the lazy DFA cache capacity (hybrid_cache_capacity) as documented, instead of the fully compiled DFA size limit. It had been forwarded to the wrong regex-automata option since the switch from the regex crate. (#307)\xHH escapes above 0x7F now match the Unicode codepoint (as UTF-8 bytes) instead of the raw byte, so e.g. \xFF matches ÿ rather than the byte 0xFF. In bytes modes the raw byte is matched as before. (#292)(?i)[à-ÿ]), which previously could miss candidate start positions. (#296)^ / $ and their multi-line variants matching at the start/end of arbitrary-byte haystacks in Ascii and UnicodeBytes bytes modes, where the match position was not a UTF-8 codepoint boundary. (#300)(a)?b(?(1)c) no longer fails to match b. (#304)(?<=(\w+)\1)x on ééx). (#310)Add a leftmost_longest feature (off by default) that adds a method to the RegexBuilder / RegexOptionsBuilder for building a VM which would operate in
leftmost_longest feature (off by default) that adds a method to the RegexBuilder/RegexOptionsBuilder for building a VM which would operate in leftmost-longest match mode instead of the regular leftmost-first mode. Useful for POSIX compliance. (#281)leftmost_longest feature (off by default) that adds a method to the RegexBuilder/RegexOptionsBuilder for building a VM which would operate in leftmost-longest match mode instead of the regular leftmost-first mode. Useful for POSIX compliance. (#281)capture_names() for a pattern with a zero-repeated named group such as (?<n>a){0} (#275)Add a perf-dfa-full feature (off by default, mirroring the regex crate) that lets regex-automata eagerly build fully compiled dense DFAs for small pat
perf-dfa-full feature (off by default, mirroring the regex crate) that lets regex-automata eagerly build fully compiled dense DFAs for small patterns, for workloads that compile few regexes and match them very heavily (#272)regex-automata dependency no longer enables the dfa-build feature by default. With dfa-build enabled, meta::Regex eagerly determinizes a full dense DFA for every small pattern, which dominated build time of simple class-containing patterns (e.g. \b(extern)\s+(crate) compiled ~4x slower than with the regex crate, which also ships without dfa-build); searches use the lazy DFA instead, with no measurable match-time difference (#272)optimize_nested_repeats pass could rewrite an optional capture group like (\w+)? into (\w*), causing an unmatched optional group to be reported as an empty match (Some("")) instead of None (#276)Matches , CaptureMatches , Captures , and SubCaptureMatches are now generic over RegexInput , which is a breaking change for code that named these typ…
BytesMode and the RegexInput trait so the matching and capture APIs can operate on strings or bytes, and allows to opt out of unicode handling if desired (#248)
RegexBuilder::disallow_empty_match_at_eof_after_newline to reject empty matches at the end of the haystack following a trailing newline, to match Oniguruma behavior (#247)RegexSet API for efficiently matching multiple patterns against the same text (#255)(?i)(\w+)\1 orders of magnitude faster on non-ASCII haystacks. The comparison is now strict fold equality over the captured text's byte-length window: a case-folded prefix of the window no longer counts as a match (previously a substring search could accept one and misalign the match end)Hir instead of a re-serialized pattern string, and RegexSet parses each pattern once for both of its set-wide engines instead of three times. This reduces compile time and peak compile memory, especially for RegexSet and small easy patternsis_match/find/find_iter and RegexSet candidate verification allocation-free per call; RegexSet::find_input no longer allocates at failed candidate positions. Short and repeated matches improve substantially (up to ~30% for small patterns, ~10% for find_iter over many matches); single very long backtracking runs, where per-run setup is fully amortized anyway, can be a few percent slowerMatches, CaptureMatches, Captures, and SubCaptureMatches are now generic over RegexInput, which is a breaking change for code that named these types explicitly (#248)(?u) / (?-u) flags are accepted when they agree with the builder configuration\G optimizations were applying where they shouldn't, giving wrong results (#256)+ only causes possessiveness after ?, * or + (#258)If you previously stored i.e. Captures, you would need to change the type to Captures<str> to get the code to compile.
Add support for \N to mean any character except newline, for Oniguruma compatibility
\N to mean any character except newline, for Oniguruma compatibility (#206)(*FAIL) backtracking control verb (#210)\p{...} and \P{...} aliases, for Oniguruma compatibility (#207)\R to mean general newline, matching all common line break characters, treating \r\n atomically (#220)(?R) CRLF mode flag (#238)\g<1> (#230)(?~abc) (#233)RegexBuilder can now build multiple patterns with the same options (#213)] (#211)Add support for "easy" variable-length lookbehinds (enabled via new feature flag) ( #194 , #196 )
\b{start}, \b{end}, \b{start-half}, \b{end-half} (#193){...} repetition syntax after assertions (except in Oniguruma mode) (#193)CompileError in Error enum to reduce size (#204)\G fails to match for increased performance (#198)ignore_whitespace case in parsing escape sequences (#193)Regex is Send and Sync (#195)Add an "oniguruma mode" flag to control whether \< and \> are treated as literals or word-boundary assertions.
\< and \> are treated as literals or word-boundary assertions. (#186)as_str is called. (#185)toy example wasn't always showing the correct analysis or compiled program when optimizations were applied. (#181)Fixed a bug whereby sometimes a backreference to a non-existing capture group would compile successfully when it should fail, causing a panic in the V
Add an optimization step after the pattern is parsed but before it is analyzed. Currently it only optimizes one specific use-case - where the expressi
^ when not in multiline mode) should now fail faster when there is no match, because fancy-regex no longer tries to match at other positions. (#170)CompileError for an invalid (numbered) backref has been updated to mention which backref was invalid (#170)Support \Z - anchor to the end of the text before any trailing newlines.
\Z - anchor to the end of the text before any trailing newlines. (#148)\O - any character including newlines. (#158)RegexBuilder: Add options for multi_line, ignore_whitespace, dot_matches_new_line (#165)RegexBuilder.case_insensitive not always applying when it should. (#163)toy example has had various bugfixes, and unit tests added. (#152, #159)Add split, splitn methods to Regex to split a string into substrings
split, splitn methods to Regex to split a string into substrings (#140)case_insensitive method to RegexBuilder to force case-insensitive mode (#132)Support for relative backreferences using \k<-1> (-1 references the previous group)
\k<-1> (-1 references the
previous group) (#121)try_replacen to Regex which returns a Result instead of panicking
when matching errors (#130)BacktrackLimitExceeded with
some patterns that you didn't get before. You can increase the backtrack limit
using RegexBuilder::backtrack_limit to help with that.[\A] used to error
but now matches the same as [A] (for compatibility with Oniguruma)(?( (#125)Support for no_std (the std feature is enabled by default but can be disabled if desired)
no_std (the std feature is enabled by default but can be
disabled if desired) (#111)TryFrom &str and String impl for Regex (#115)Error and its components are now Clone (#116)Support for conditionals: using a regex like (? a)?b(?(test)c|d) will try to match c after b if a matched in the capture group named test, otherwise d
(?<test>a)?b(?(test)c|d) will try to match c after b if a matched in the capture group named
test, otherwise d after b if a wasn't captured into the test group.Support for \G (anchor to end of previous match): Using a regex like \G\w will match each letter of foo in foo bar but nothing else.
\G (anchor to end of previous match): Using a regex
like \G\w will match each letter of foo in foo bar but
nothing else.Support for \K (keep out): Using a regex like @\K\w+ will match things like @foo but the resulting match text will only include foo, keeping out the @
\K (keep out): Using a regex like @\K\w+ will match
things like @foo but the resulting match text will only include
foo, keeping out the @.Allow users to disable any of the unicode and perf-* features of the regex crate. Disabling these features can reduce compile time and/or binary size
unicode and perf-* features of
the regex crate. Disabling these features can reduce compile time
and/or binary size for use cases where these features are not needed.
(All features remain enabled by default.)Fix panic on incomplete escape sequences in input regexes
+ in (?=hello)+Regex now has replace methods like the regex crate:
Regex now has replace methods like the regex crate:
replace - single replacementreplace_all - replace all non-overlapping matchesreplacen - configurable number of replacementsRegex now implements Clone, Display, FromStr
Regex now implements Clone, Display, FromStrCaptures now implements Index<usize> to access captures by number
and Index<&str> to access by nameMethods find_iter and captures_iter to iterate over all non-overlapping matches for a string
find_iter and captures_iter to iterate over all
non-overlapping matches for a stringfind_from_pos to find starting from a specific positionescape function to escape special characters in a string so that it matches literally
escape function to escape special characters in a string so that it
matches literallySupport for named groups and backrefs:
(?<name>...) or (?P<name>...)\k<name> or (?P=name)Captures::name to get matched group by nameRegex::capture_names to get capture names in regexCaptures::expand for regex crate compatible syntaxExpander for python-compatible syntax and advanced usageMatch::range and some From impls for convenienceInclude string snippet in errors for unknown group and invalid escape to make it easier to identify the problem.
Support comments using (?# comment) syntax
(?# comment) syntax\u21D2 and \U0001F60AOptimization: Delegate const-sized suffixes in more cases
captures_read_at when delegating to regex crateSome regexes with fancy parts in the beginning/middle didn't match when they should have, e.g. ((?!x)(a|ab))c didn't match abc.
((?!x)(a|ab))c didn't match abc.Add delegate_size_limit and delegate_dfa_size_limit to RegexBuilder to allow configuring these limits for regex crate.
delegate_size_limit and delegate_dfa_size_limit to
RegexBuilder to allow configuring these limits for regex crate.Add limit for backtracking so that execution errors instead of running for a long time in case of catastrophic backtracking.
RegexBuilder with backtrack_limit to configure the new
backtrack limit per regex.Error now implements std::error::Error traitChange find to return a Match struct (breaking change)
(?>foo) group syntax and the
a++, a*+ and a?+ possessive syntax\b, \f, \t, \n, \r, \vDebug for Regexfind to return a Match struct (breaking change)Captures API (breaking change):
at and pos with get that returns a Match structis_empty (use len)] and } as literals{ as literal when not after atom\< or \e inside character classes\x{...} escape(a|)] in character classes[Unreleased]: https://github.com/fancy-regex/fancy-regex/compare/0.20.2...HEAD [0.20.2]: https://github.com/fancy-regex/fancy-regex/compare/0.20.1...0
One column per quarter.