More PHP rules to write efficient, error-free and safe regular expressions

Hello PHP developers,

This is to announce that we added 8 new rules to help you write regular expressions. These rules are coming on top of the 8 existing regexp rules we released in Sept on SonarCloud.
You now have 16 rules to write efficient, error-free and safe regular expressions.
Here are the list of the ones we added with this update:

Bug Detection Rules:

  • S5856: Regular expressions should be syntactically valid
  • S6001: Back references in regular expressions should only refer to capturing groups that are matched before the reference
  • S6002: Regex lookahead assertions
  • S5850: Alternatives in regular expressions should be grouped when used with anchors

Code Smell Detection Rules:

  • S6019: Reluctant quantifiers in regular expressions should be followed by an expression that can’t match the empty string
  • S5843: Regular expressions should not be too complicated
  • S5867: Unicode-aware versions of character classes should be preferred
  • S5857: Character classes should be preferred over reluctant quantifiers in regular expressions

These rules are available now on SonarCloud and will be included in SonarQube 9.2


1 Like