Disallow backreferences that reference a group that might not be matched.
configuration in plugin:clean-regex/recommended
: "warn"
If the referenced group of a backreference is not matched because some other path leads to the backreference, the backreference will be replaced with the empty string. The same will happen if the captured text of the referenced group was reset before reaching the backreference.
This will handle backreferences which will always be replaced with the empty
string for the above reason. Use no-empty-backreference
for that.
Examples of valid code for this rule:
/(a+)b\1/
/(a+)b|\1/ // this will be done by no-empty-backreference
Examples of invalid code for this rule:
/(a)?b\1/
/((a)|c)+b\1/