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

org.sonar.l10n.py.rules.python.S5842.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

Why is this an issue?

A regex should never include a repetitive pattern whose body would match the empty string. This is usually a sign that a part of the regex is redundant or does not do what the author intended.

Noncompliant code example

r"(?:)*"      # same as the empty regex, the '*' accomplishes nothing
r"(?:|x)*"    # same as the empty regex, the alternative has no effect
r"(?:x|)*"    # same as 'x*', the empty alternative has no effect
r"(?:x*|y*)*" # same as 'x*', the first alternative would always match, y* is never tried
r"(?:x?)*"    # same as 'x*'
r"(?:x?)+"    # same as 'x*'

Compliant solution

r"x*"




© 2015 - 2024 Weber Informatics LLC | Privacy Policy