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

**URL:** <https://community.sonarsource.com/t/more-php-rules-to-write-efficient-error-free-and-safe-regular-expressions/52193>\
**Category:** Sonar Updates\
**Tags:** regex, php\
**Created:** [October 27, 2021, 11:46am UTC](https://community.sonarsource.com/t/more-php-rules-to-write-efficient-error-free-and-safe-regular-expressions/52193 "2021-10-27T11:46:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Gigleux](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_gigleux/32/26_2.png) [@Alexandre\_Gigleux](https://community.sonarsource.com/u/Alexandre_Gigleux)\
**Post date:** [October 27, 2021, 11:46am UTC](https://community.sonarsource.com/t/more-php-rules-to-write-efficient-error-free-and-safe-regular-expressions/52193/1 "2021-10-27T11:46:39Z")

</div>

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](https://community.sonarsource.com/t/write-efficient-error-free-and-safe-regular-expressions-regex-in-php/49808) we released in Sept on SonarCloud.  
You now have [16 rules](https://rules.sonarsource.com/php/tag/regex) 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](https://rules.sonarsource.com/php/tag/regex/RSPEC-5856): Regular expressions should be syntactically valid
- [S6001](https://rules.sonarsource.com/php/tag/regex/RSPEC-6001): Back references in regular expressions should only refer to capturing groups that are matched before the reference
- [S6002](https://rules.sonarsource.com/php/tag/regex/RSPEC-6002): Regex lookahead assertions
- [S5850](https://rules.sonarsource.com/php/tag/regex/RSPEC-5850): Alternatives in regular expressions should be grouped when used with anchors

Code Smell Detection Rules:

- [S6019](https://rules.sonarsource.com/php/tag/regex/RSPEC-6019): Reluctant quantifiers in regular expressions should be followed by an expression that can’t match the empty string
- [S5843](https://rules.sonarsource.com/php/tag/regex/RSPEC-5843): Regular expressions should not be too complicated
- [S5867](https://rules.sonarsource.com/php/tag/regex/RSPEC-5867): Unicode-aware versions of character classes should be preferred
- [S5857](https://rules.sonarsource.com/php/tag/regex/RSPEC-5857): Character classes should be preferred over reluctant quantifiers in regular expressions

These rules are available now on [SonarCloud](https://sonarcloud.io/) and will be included in SonarQube 9.2

Alex
