v4.0.0
This release focused on improving and simplifying the API for advanced options and plugins. With the new features, all JavaScript-based tools that provide regex search or replace can now benefit from adopting regex
.
🚨 Breaking
- The previously experimental/debugging options
__flagX
,__flagN
,__flagV
, and__extendSyntax
have been redesigned and renamed, and are now documented features via the new optionsdisable: {x, n, v, atomic, subroutines}
andforce: {v}
. The__rake
option has been removed, and its behavior is now applied whenever flag x is enabled. - The ability to provide an alternate
RegExp
constructor by modifyingthis
has been removed. - Renamed option
postprocessors
asplugins
. - Plugins now receive flags as a property of their second argument.
🚀 Features
- New option
subclass: true
results in numbered backreferences used outside of the regex automatically referencing their correct groups, in all contexts. The underlying issue is that emulating extended syntax (atomic groups and subroutines) sometimes requires adding anonymous "emulation group" captures to generated regex source. This was already mostly a non-issue because implicit flag n requires the use of named groups. This new option makes it safe to disable n and rely on group numbers while using extended syntax. - New option
unicodeSetsPlugin
allows overriding or removing the built-in backward compatibility for environments without native support for flag v. - When using atomic groups, numbered backreferences within the regex (from interpolated regexes, or when flag n is disabled) are now supported and automatically adjusted (previously threw a descriptive error).
- Improved TypeScript types and introduced type tests, with extensive help and advice from @benblank.
- The flags provided to plugins now include the implicit v or u (whichever will be used, based on provided options and the environment's native support for v).
- The built-in backcompat layer no longer throws in the edge case of using doubly-negated
[^\P{…}]
with flag i in environments that don't natively support flag v, since the handling was incomplete and the syntax is not always problematic. New optionunicodeSetsPlugin
allows providing a more robust v transpiler, if needed.
🐞 Fixes
- Fixed backreference adjustments when atomic groups contain capturing groups.