All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.php.rules.php.S5855.html Maven / Gradle / Ivy

This rule raises an issue when multiple branches of a regex alternative match the same input.

Why is this an issue?

If an alternative in a regular expression only matches things that are already matched by another alternative, that alternative is redundant and serves no purpose.

In the best case this means that the offending subpattern is merely redundant and should be removed. In the worst case it’s a sign that this regex does not match what it was intended to match and should be reworked.

Code examples

Noncompliant code example

"/[ab]|a/"   // Noncompliant: the "|a" is redundant because "[ab]" already matches "a"
"/.*|a/"     // Noncompliant: .* matches everything, so any other alternative is redundant

Compliant solution

"/[ab]/"
"/.*/"




© 2015 - 2025 Weber Informatics LLC | Privacy Policy