fancy-regex
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.
0.19.0
205M downloads/mo
#497 most downloaded on crates.io
fancy-regex/fancy-regex
What this package is like to depend on
Last release 26 days ago
28 Jul 2026
Release timing varies
gaps range from 4 weeks to 10 months
Nearly every release is documented
notes for 28 of 28 stable releases
Nothing withdrawn
no release was ever pulled
10 years old
28 releases · first in 2017
4 releases in the last 12 months
see the full history below
Release timeline
28 releases · Feb 2017 to Jul 2026Releases
latest 28-
0.19.028 Jul 2026Release notes
Open source →Added
- Add
BytesModeand theRegexInputtrait so the matching and capture APIs can operate on strings or bytes, and allows to opt out of unicode handling if desired (#248) - Add experimental seek optimization to only invoke the VM at candidate positions where a match could occur (#246)
- Add
RegexBuilder::disallow_empty_match_at_eof_after_newlineto reject empty matches at the end of the haystack following a trailing newline, to match Oniguruma behavior (#247) - Add
RegexSetAPI for efficiently matching multiple patterns against the same text (#255)
Changed
- Case-insensitive backreference comparison of non-ASCII text now uses direct Unicode simple case folding instead of building a regex engine per comparison, which makes patterns like
(?i)(\w+)\1orders 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) - Compilation performance: delegated regex-automata engines (including the whole pattern in the easy case) are now built from a directly-constructed
Hirinstead of a re-serialized pattern string, andRegexSetparses each pattern once for both of its set-wide engines instead of three times. This reduces compile time and peak compile memory, especially forRegexSetand small easy patterns - Match performance: the backtracking VM's working memory (saves, backtrack stack, delegate slots) is pooled and reused across runs, making
is_match/find/find_iterandRegexSetcandidate verification allocation-free per call;RegexSet::find_inputno longer allocates at failed candidate positions. Short and repeated matches improve substantially (up to ~30% for small patterns, ~10% forfind_iterover many matches); single very long backtracking runs, where per-run setup is fully amortized anyway, can be a few percent slower Matches,CaptureMatches,Captures, andSubCaptureMatchesare now generic overRegexInput, which is a breaking change for code that named these types explicitly (#248)- Patterns no longer force Unicode mode during parsing, and inline
(?u)/(?-u)flags are accepted when they agree with the builder configuration
Fixed
- Fix bug whereby inline flags were not overriding the builder options (#247)
- Fix bug whereby
\Goptimizations were applying where they shouldn't, giving wrong results (#256) - Support Oniguruma quantifier parsing rules, whereby swapped ordering causes possessiveness,
+only causes possessiveness after?,*or+(#258)
Upgrade guide
If you previously stored i.e.
Captures, you would need to change the type toCaptures<str>to get the code to compile.Release notes
Open source →Added
- Add
BytesModeand theRegexInputtrait so the matching and capture APIs can operate on strings or bytes, and allows to opt out of unicode handling if desired (#248)- Also allows searching within a range without slicing (#253)
- Assertions can be overridden at runtime, if the regex builder
allow_input_assertion_overridesoption was used (#254) - Search can be performed in anchored mode, searching only at the start position specified (#263)
- Add experimental seek optimization to only invoke the VM at candidate positions where a match could occur (#246)
- Add
RegexBuilder::disallow_empty_match_at_eof_after_newlineto reject empty matches at the end of the haystack following a trailing newline, to match Oniguruma behavior (#247) - Add
RegexSetAPI for efficiently matching multiple patterns against the same text (#255)
Changed
- Case-insensitive backreference comparison of non-ASCII text now uses direct Unicode simple case folding instead of building a regex engine per comparison, which makes patterns like
(?i)(\w+)\1orders 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) - Compilation performance: delegated regex-automata engines (including the whole pattern in the easy case) are now built from a directly-constructed
Hirinstead of a re-serialized pattern string, andRegexSetparses each pattern once for both of its set-wide engines instead of three times. This reduces compile time and peak compile memory, especially forRegexSetand small easy patterns - Match performance: the backtracking VM's working memory (saves, backtrack stack, delegate slots) is pooled and reused across runs, making
is_match/find/find_iterandRegexSetcandidate verification allocation-free per call;RegexSet::find_inputno longer allocates at failed candidate positions. Short and repeated matches improve substantially (up to ~30% for small patterns, ~10% forfind_iterover many matches); single very long backtracking runs, where per-run setup is fully amortized anyway, can be a few percent slower Matches,CaptureMatches,Captures, andSubCaptureMatchesare now generic overRegexInput, which is a breaking change for code that named these types explicitly (#248)- Patterns no longer force Unicode mode during parsing, and inline
(?u)/(?-u)flags are accepted when they agree with the builder configuration
Fixed
- Fix bug whereby inline flags were not overriding the builder options (#247)
- Fix bug whereby
\Goptimizations were applying where they shouldn't, giving wrong results (#256) - Support Oniguruma quantifier parsing rules, whereby swapped ordering causes possessiveness,
+only causes possessiveness after?,*or+(#258)
Upgrade guide
If you previously stored i.e.
Captures, you would need to change the type toCaptures<str>to get the code to compile. - Add
-
0.18.024 Apr 2026Release notes
Open source →Added
- Add support for
\Nto mean any character except newline, for Oniguruma compatibility (#206) - Add support for
(*FAIL)backtracking control verb (#210) - Add support for more
\p{...}and\P{...}aliases, for Oniguruma compatibility (#207) - Add support for word boundaries and zero-length fancy patterns inside variable lookbehinds (at top level) (#216)
- Add support for
\Rto mean general newline, matching all common line break characters, treating\r\natomically (#220) - Add support for the regex crate's
(?R)CRLF mode flag (#238) - Add support for subroutine calls (including recursion up to 20 levels deep, matching Oniguruma behavior)
\g<1>(#230) - Add support for Oniguruma's absent repeater
(?~abc)(#233) - Add support for ignoring empty matches (#240)
- Add support for treating unnamed capture groups as non-capturing when named groups exist (#241)
Changed
RegexBuildercan now build multiple patterns with the same options (#213)- Parsing of capture group names is now more lenient (#241)
Fixed
- Fixed bug with parsing nested character classes containing unescaped
](#211)
Release notes
Open source →Added
- Add support for
\Nto mean any character except newline, for Oniguruma compatibility (#206) - Add support for
(*FAIL)backtracking control verb (#210) - Add support for more
\p{...}and\P{...}aliases, for Oniguruma compatibility (#207) - Add support for word boundaries and zero-length fancy patterns inside variable lookbehinds (at top level) (#216)
- Add support for
\Rto mean general newline, matching all common line break characters, treating\r\natomically (#220) - Add support for the regex crate's
(?R)CRLF mode flag (#238) - Add support for subroutine calls (including recursion up to 20 levels deep, matching Oniguruma behavior)
\g<1>(#230) - Add support for Oniguruma's absent repeater
(?~abc)(#233) - Add support for ignoring empty matches (#240)
- Add support for treating unnamed capture groups as non-capturing when named groups exist (#241)
Changed
RegexBuildercan now build multiple patterns with the same options (#213)- Parsing of capture group names is now more lenient (#241)
Fixed
- Fixed bug with parsing nested character classes containing unescaped
](#211)
- Add support for
-
0.17.013 Dec 2025Release notes
Open source →Added
- Add support for "easy" variable-length lookbehinds (enabled via new feature flag) (#194, #196)
- Add support for more word boundaries:
\b{start},\b{end},\b{start-half},\b{end-half}(#193) - Allow
{...}repetition syntax after assertions (except in Oniguruma mode) (#193) - Add Oniguruma mode flag to playground (#199)
Changed
- Rewrite Theory section of Readme in a more formal style (#187)
- Box
CompileErrorinErrorenum to reduce size (#204) - Bail out early when
\Gfails to match for increased performance (#198) - Handle
ignore_whitespacecase in parsing escape sequences (#193) - Add tests to ensure that
RegexisSendandSync(#195)
Fixed
- Fix clippy lint warnings (#204)
Release notes
Open source →Added
- Add support for "easy" variable-length lookbehinds (enabled via new feature flag) (#194, #196)
- Add support for more word boundaries:
\b{start},\b{end},\b{start-half},\b{end-half}(#193) - Allow
{...}repetition syntax after assertions (except in Oniguruma mode) (#193) - Add Oniguruma mode flag to playground (#199)
Changed
- Rewrite Theory section of Readme in a more formal style (#187)
- Box
CompileErrorinErrorenum to reduce size (#204) - Bail out early when
\Gfails to match for increased performance (#198) - Handle
ignore_whitespacecase in parsing escape sequences (#193) - Add tests to ensure that
RegexisSendandSync(#195)
Fixed
- Fix clippy lint warnings (#204)
-
0.16.219 Sep 2025Release notes
Open source →Added
- Add an "oniguruma mode" flag to control whether
\<and\>are treated as literals or word-boundary assertions. (#186) - Add support for const-size backrefs in lookbehinds. (#182)
Changed
- A few small internal changes which allowed us to expose a web-based playground for fancy-regex. (#181)
Fixed
- Fix behavior of repetition on an empty match. (#179)
- Always return the original input pattern when
as_stris called. (#185) - Fix panic when matching non-ascii text as part of a case insensitive backref. (#189)
- The
toyexample wasn't always showing the correct analysis or compiled program when optimizations were applied. (#181)
Release notes
Open source →Added
- Add an "oniguruma mode" flag to control whether
\<and\>are treated as literals or word-boundary assertions. (#186) - Add support for const-size backrefs in lookbehinds. (#182)
Changed
- A few small internal changes which allowed us to expose a web-based playground for fancy-regex. (#181)
Fixed
- Fix behavior of repetition on an empty match. (#179)
- Always return the original input pattern when
as_stris called. (#185) - Fix panic when matching non-ascii text as part of a case insensitive backref. (#189)
- The
toyexample wasn't always showing the correct analysis or compiled program when optimizations were applied. (#181)
- Add an "oniguruma mode" flag to control whether
-
0.16.102 Aug 2025Release notes
Open source →Fixed
- 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 VM when trying to match the regex. (#174)
Release notes
Open source →Fixed
- 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 VM when trying to match the regex. (#174)
- Fixed a bug whereby sometimes a backreference to a non-existing capture group would compile successfully
-
0.16.001 Aug 2025Release notes
Open source →Added
- Add an optimization step after the pattern is parsed but before it is analyzed.
Currently it only optimizes one specific use-case - where the expression is easy except
for a trailing positive lookahead whose contents are also easy. The optimization is to delegate to the regex crate instead of using the backtracking VM. (#171)
Changed
- Patterns which are anchored to the start of the text (i.e. with
^when not in multiline mode) should now fail faster when there is no match, becausefancy-regexno longer tries to match at other positions. (#170) - The
CompileErrorfor an invalid (numbered) backref has been updated to mention which backref was invalid (#170) - Removed dependency on derivative (#169)
Fixed
- Fixed a bug whereby sometimes a capture group containing a backref to itself would cause a compile error, when it is valid - this fixes a few Oniguruma test cases (#170)
Release notes
Open source →Added
- Add an optimization step after the pattern is parsed but before it is analyzed. Currently it only optimizes one specific use-case - where the expression is easy except for a trailing positive lookahead whose contents are also easy. The optimization is to delegate to the regex crate instead of using the backtracking VM. (#171)
Changed
- Patterns which are anchored to the start of the text (i.e. with
^when not in multiline mode) should now fail faster when there is no match, becausefancy-regexno longer tries to match at other positions. (#170) - The
CompileErrorfor an invalid (numbered) backref has been updated to mention which backref was invalid (#170) - Removed dependency on derivative (#169)
Fixed
- Fixed a bug whereby sometimes a capture group containing a backref to itself would cause a compile error, when it is valid - this fixes a few Oniguruma test cases (#170)
- Add an optimization step after the pattern is parsed but before it is analyzed.
-
0.15.006 Jul 2025Release notes
Open source →Added
- Support
\Z- anchor to the end of the text before any trailing newlines. (#148) - Support
\O- any character including newlines. (#158) - The parser can now parse subroutine calls and relative backreferences (but execution is still unsupported). This is preparation for future work. Some new error variants have been added for features which can be parsed but are still otherwise unsupported.
- Backreferences can now be case insensitive. (#160)
RegexBuilder: Add options formulti_line,ignore_whitespace,dot_matches_new_line(#165)
Fixed
Release notes
Open source →Added
- Support
\Z- anchor to the end of the text before any trailing newlines. (#148) - Support
\O- any character including newlines. (#158) - The parser can now parse subroutine calls and relative backreferences (but execution is still unsupported). This is preparation for future work. Some new error variants have been added for features which can be parsed but are still otherwise unsupported.
- Backreferences can now be case insensitive. (#160)
RegexBuilder: Add options formulti_line,ignore_whitespace,dot_matches_new_line(#165)
Fixed
- Fix infinite loop when backtracking limit is hit (#153)
- Fix
RegexBuilder.case_insensitivenot always applying when it should. (#163) - The
toyexample has had various bugfixes, and unit tests added. (#152, #159)
- Support
-
0.14.024 Oct 2024Release notes
Open source →Added
- Add
split,splitnmethods toRegexto split a string into substrings (#140) - Add
case_insensitivemethod toRegexBuilderto force case-insensitive mode (#132)
Changed
- Bump bit-set dependency to 0.8 (#139)
Release notes
Open source →Added
- Add
split,splitnmethods toRegexto split a string into substrings (#140) - Add
case_insensitivemethod toRegexBuilderto force case-insensitive mode (#132)
Changed
- Bump bit-set dependency to 0.8 (#139)
- Add
-
0.13.022 Dec 2023Release notes
Open source →Added
- Support for relative backreferences using
\k<-1>(-1 references the
previous group) (#121) - Add
try_replacentoRegexwhich returns aResultinstead of panicking
when matching errors (#130)
Changed
- Switch from regex crate to regex-automata and regex-syntax (lower level APIs)
to simplify internals (#121) - Note: Due to above change, more backtracking is done in fancy-regex itself
instead of regex-automata, and you might get aBacktrackLimitExceededwith
some patterns that you didn't get before. You can increase the backtrack limit
usingRegexBuilder::backtrack_limitto help with that. - Allow escaping some letters in character classes, e.g.
[\A]used to error
but now matches the same as[A](for compatibility with Oniguruma) - MSRV (minimum supported Rust version) is now 1.66.1 (from 1.61.0)
Fixed
- Fix index out of bounds panic when parsing unclosed
(?((#125)
Release notes
Open source →Added
- Support for relative backreferences using
\k<-1>(-1 references the previous group) (#121) - Add
try_replacentoRegexwhich returns aResultinstead of panicking when matching errors (#130)
Changed
- Switch from regex crate to regex-automata and regex-syntax (lower level APIs) to simplify internals (#121)
- Note: Due to above change, more backtracking is done in fancy-regex itself
instead of regex-automata, and you might get a
BacktrackLimitExceededwith some patterns that you didn't get before. You can increase the backtrack limit usingRegexBuilder::backtrack_limitto help with that. - Allow escaping some letters in character classes, e.g.
[\A]used to error but now matches the same as[A](for compatibility with Oniguruma) - MSRV (minimum supported Rust version) is now 1.66.1 (from 1.61.0)
Fixed
- Fix index out of bounds panic when parsing unclosed
(?((#125)
- Support for relative backreferences using
-
0.12.011 Nov 2023Release notes
Open source →Added
- Support for
no_std(thestdfeature is enabled by default but can be
disabled if desired) (#111) TryFrom&strandStringimpl forRegex(#115)
Changed
Errorand its components are nowClone(#116)- MSRV (minimum supported Rust version) is now 1.61.0 (from 1.42.0)
Release notes
Open source →Added
- Support for
no_std(thestdfeature is enabled by default but can be disabled if desired) (#111) TryFrom&strandStringimpl forRegex(#115)
Changed
Errorand its components are nowClone(#116)- MSRV (minimum supported Rust version) is now 1.61.0 (from 1.42.0)
- Support for
-
0.11.012 Jan 2023Release notes
Open source →Added
- Support for conditionals: using a regex like
(?<test>a)?b(?(test)c|d)will try to matchcafterbifamatched in the capture group namedtest, otherwisedafterbifawasn't captured into thetestgroup.
Changed
- Updated parse errors to show the position they occurred at.
Fixed
- Fix panic when backref is used within referenced group itself and group end index is not known yet (#103)
- Support for conditionals: using a regex like
-
0.10.028 Apr 2022Release notes
Open source →Added
- Support for
\G(anchor to end of previous match): Using a regex like\G\wwill match each letter offooinfoo barbut nothing else.
- Support for
-
0.9.021 Apr 2022Release notes
Open source →Added
- Support for
\K(keep out): Using a regex like@\K\w+will match things like@foobut the resulting match text will only includefoo, keeping out the@.
- Support for
-
0.8.022 Feb 2022Release notes
Open source →Added
- Allow users to disable any of the
unicodeandperf-*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.)
Changed
- MSRV (minimum supported Rust version) is now 1.42.0 (from 1.41.1)
- Allow users to disable any of the
-
0.7.129 Jul 2021Release notes
Open source →Fixed
- Fix panic on incomplete escape sequences in input regexes
- Disallow quantifers on lookarounds and other zero-width assertion
expressions, e.g. the
+in(?=hello)+
-
0.7.012 Jul 2021Release notes
Open source →Added
Regexnow has replace methods like the regex crate:replace- single replacementreplace_all- replace all non-overlapping matchesreplacen- configurable number of replacements
-
0.6.017 May 2021Release notes
Open source →Added
Regexnow implementsClone,Display,FromStrCapturesnow implementsIndex<usize>to access captures by number andIndex<&str>to access by name
-
0.5.015 Feb 2021Release notes
Open source →Added
- Methods
find_iterandcaptures_iterto iterate over all non-overlapping matches for a string - Method
find_from_postofindstarting from a specific position
Changed
- MSRV (minimum supported Rust version) is now 1.41.1 (from 1.32.0)
- Methods
-
0.4.109 Nov 2020Release notes
Open source →Added
escapefunction to escape special characters in a string so that it matches literally
-
0.4.027 Sep 2020Release notes
Open source →Added
- Support for named groups and backrefs:
- Capture with
(?<name>...)or(?P<name>...) - Backref with
\k<name>or(?P=name) Captures::nameto get matched group by nameRegex::capture_namesto get capture names in regex
- Capture with
- Support for expanding matches using a replacement template string
Captures::expandfor regex crate compatible syntax- See
Expanderfor python-compatible syntax and advanced usage
Match::rangeand someFromimpls for convenience
- Support for named groups and backrefs:
-
0.3.528 Apr 2020Release notes
Open source →Changed
- Include string snippet in errors for unknown group and invalid escape to make it easier to identify the problem.
-
0.3.428 Apr 2020Release notes
Open source →Added
- Support comments using
(?# comment)syntax - Support unicode escapes like
\u21D2and\U0001F60A
- Support comments using
-
0.3.328 Feb 2020Release notes
Open source →Changed
- Optimization: Delegate const-sized suffixes in more cases
- Optimization: Use
captures_read_atwhen delegating to regex crate
-
0.3.205 Feb 2020Release notes
Open source →Fixed
- Some regexes with fancy parts in the beginning/middle didn't match
when they should have, e.g.
((?!x)(a|ab))cdidn't matchabc.
- Some regexes with fancy parts in the beginning/middle didn't match
when they should have, e.g.
-
0.3.109 Dec 2019Release notes
Open source →Added
- Add
delegate_size_limitanddelegate_dfa_size_limittoRegexBuilderto allow configuring these limits for regex crate.
- Add
-
0.3.027 Nov 2019Release notes
Open source →Added
- Add limit for backtracking so that execution errors instead of running for a long time in case of catastrophic backtracking.
- Add
RegexBuilderwithbacktrack_limitto configure the new backtrack limit per regex. Errornow implementsstd::error::Errortrait
Fixed
- Fix panic in backref matching with multibyte chars
-
0.2.018 Oct 2019Release notes
Open source →Added
- More documentation and examples
- Support character class nesting and intersections (implemented in regex crate)
- Support atomic groups, both the the
(?>foo)group syntax and thea++,a*+anda?+possessive syntax - Support
\b,\f,\t,\n,\r,\v - Support look-behind with variable sized alternative
- Implement
DebugforRegex - More test coverage including running one of Oniguruma's test suites
Changed
- Change
findto return aMatchstruct (breaking change) - Change
CapturesAPI (breaking change):- Replace
atandposwithgetthat returns aMatchstruct - Remove
is_empty(uselen)
- Replace
- Allow unescaped
]and}as literals - Allow unescaped
{as literal when not after atom - Allow escapes such as
\<or\einside character classes - Allow up to 8 characters in
\x{...}escape - Allow escaping of space to make literal space
- Allow
(a|) - Reject invalid backreferences
Fixed
- Multiple fixes for alternatives in look-arounds
- Fix hex escape to not include letters after "F"
- Fix handling of unescaped
]in character classes - Fix case insensitive character classes and other escapes
- Don't ignore spaces in character classes even with "comment mode"
-
0.1.005 Feb 2017