diff --git a/src/Currency.php b/src/Currency.php index fffcd3b..4eafbf4 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -117,10 +117,15 @@ public function format($value, $code = null) $format = $this->getCurrencyProp($code, 'format'); // Value Regex - $valRegex = '/([0-9].*|)[0-9]/'; + $valRegex = '/(?:[0-9].*|)[0-9]/'; + + // Match value format string + preg_match($valRegex, $format, $valFormat); + + $valFormat = $valFormat[0]; // Match decimal and thousand separators - preg_match_all('/[\s\',.!]/', $format, $separators); + preg_match_all('/[\s\',.!]/', $valFormat, $separators); if ($thousand = array_get($separators, '0.0', null)) { if ($thousand == '!') { @@ -130,11 +135,6 @@ public function format($value, $code = null) $decimal = array_get($separators, '0.1', null); - // Match format for decimals count - preg_match($valRegex, $format, $valFormat); - - $valFormat = array_get($valFormat, 0, 0); - // Count decimals length $decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0; @@ -142,7 +142,7 @@ public function format($value, $code = null) $value = number_format($value, $decimals, $decimal, $thousand); // Return the formatted measurement - return preg_replace($valRegex, $value, $format); + return str_replace($valFormat, $value, $format); } /**