Skip to content

v4.0.0

Compare
Choose a tag to compare
@slevithan slevithan released this 06 Aug 17:08
· 172 commits to main since this release

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 options disable: {x, n, v, atomic, subroutines} and force: {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 modifying this has been removed.
  • Renamed option postprocessors as plugins.
  • 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 option unicodeSetsPlugin allows providing a more robust v transpiler, if needed.

🐞 Fixes

  • Fixed backreference adjustments when atomic groups contain capturing groups.