Last active
July 3, 2018 22:25
-
-
Save gabriel-felipe/af31fbc7ed89432a942ada30727454ec to your computer and use it in GitHub Desktop.
Regex Replace PHP Operations by BCMath functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YOU SHOULD NOT BLINDLY REPLACE USING THESE REGEX, FALSE POSITIVES ARE POSSIBLE. | |
These were written to make the job easier, but it still needs checking. | |
Adding var regex, replaces $var1 + $var2 by bcadd($Var1, $var2, 2) | |
Regex: (\$[\$\'\'\"\"\[\]\_A-z0-9]+?)[\s]*\+[\s]*([\$\'\'\"\"\[\]\_A-z0-9]+) | |
Replace: bcadd($1,$2) | |
Replaces $var1 += $var2 by $var1 = bcadd($var1,$var2) | |
Regex: (\$[\$\'\'\"\"\[\]\_A-z0-9]+?)[\s]*\+\=[\s]*(\$[\$\'\'\"\"\[\]\_A-z0-9]+) | |
Replace: $1 = bcadd($1,$2) | |
Same as the previous one, but includes function calls and needs to have a ; at the end, so it would replace for example: | |
$var1 += round($var2, 2); by $var1 = bcadd($var1,round($var2, 2); | |
Regex: ([^\s]+)[\s]*\+\=[\s]*([^\s]+); | |
Replace: $1 = bcadd($1,$2); | |
Subtracting var regex, replaces $var1 - $var2 by bcsub($var1, $var2) | |
Regex: (\$[\$\'\'\"\"\[\]\_A-z0-9]+?)[\s]*\-[\s]*([\$\'\'\"\"\[\]\_A-z0-9]+) | |
Replace: bcsub($1,$2); | |
Regex: (\$[\$\'\'\"\"\[\]\_A-z0-9]+?)[\s]*\-\=[\s]*(\$[\$\'\'\"\"\[\]\_A-z0-9]+) | |
Replace: $1 = bcsub($1,$2) | |
Same as the previous one, but includes function calls and needs to have a ; at the end, so it would replace for example: | |
$var1 -= round($var2, 2); by $var1 = bcadd($var1,round($var2, 2); | |
Regex: ([^\s]+)[\s]*\-\=[\s]*([^\s]+); | |
Replace: $1 = bcsub($1,$2); | |
Multiplying var regex, replaces $var1 * $var2 by bcmul($var1, $var2) | |
Regex: (\$[\$\'\'\"\"\[\]\_A-z0-9]+?)[\s]*\*[\s]*([\$\'\'\"\"\[\]\_A-z0-9]+) | |
Replace: bcmul($1,$2) | |
Dividing var regex, replaces $var1 / $var2 by bcdiv($var1, $var2) | |
Regex: (\$[\$\'\'\"\"\[\]\_A-z0-9]+?)[\s]*\\[\s]*([\$\'\'\"\"\[\]\_A-z0-9]+) | |
Replace: bcdiv($1,$2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment