1.2.1135. Simplify Regex¶
Avoid using regex when the searched string or the replacement are simple enough.
PRCE regex are a powerful way to search inside strings, but they also come at the price of performance. When the query is simple enough, try using strpos() or stripos() instead.
<?php
// simple preg calls
if (preg_match('/a/', $string)) {}
if (preg_match('/b/i', $string)) {} // case insensitive
// light replacements
if( strpos('a', $string)) {}
if( stripos('b', $string)) {} // case insensitive
?>
1.2.1135.1. Connex PHP features¶
1.2.1135.1.1. Suggestions¶
Use str_replace(), strtr() or even strpos()
1.2.1135.1.2. Specs¶
Short name |
Structures/SimplePreg |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |