SonarCloud helps PHP developers simplify the complexity of their regular expressions

Hello PHP developers,

It’s easy to create complex regular expressions that over time become difficult to read and maintain. This is why we added 9 rules focusing on helping you to rewrite these complex regular expressions in a more readable and maintainable way.

Here are the 9 new rules:

  • S6393: Regular expressions should have valid delimiters
  • S6396: Superfluous curly brace quantifiers should be avoided
  • S6397: Character classes in regular expressions should not contain only one character
  • S6323: Alternation in regular expressions should not contain empty alternatives
  • S6326: Regular expressions should not contain multiple spaces
  • S6353: Regular expression quantifiers and character classes should be used concisely
  • S6328: Replacement strings should reference existing regular expression groups
  • S6331: Regular expressions should not contain empty groups
  • S6395: Non-capturing groups without quantifier should not be used

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

Alex

3 Likes