From 8e7771cde1a6b9b9e024fb212f6ff4df60b62974 Mon Sep 17 00:00:00 2001 From: Nathan Dench Date: Thu, 13 May 2021 11:13:05 +1000 Subject: [PATCH] Create R1C1_COORDINATE_REGEX constant --- src/PhpSpreadsheet/Cell/AddressHelper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PhpSpreadsheet/Cell/AddressHelper.php b/src/PhpSpreadsheet/Cell/AddressHelper.php index f9177808..cf5b0347 100644 --- a/src/PhpSpreadsheet/Cell/AddressHelper.php +++ b/src/PhpSpreadsheet/Cell/AddressHelper.php @@ -6,6 +6,8 @@ use PhpOffice\PhpSpreadsheet\Exception; class AddressHelper { + public const R1C1_COORDINATE_REGEX = '/(R((?:\[-?\d*\])|(?:\d*))?)(C((?:\[-?\d*\])|(?:\d*))?)/i'; + /** * Converts an R1C1 format cell address to an A1 format cell address. */ @@ -72,7 +74,7 @@ class AddressHelper foreach ($temp as &$value) { // Only replace in alternate array entries (i.e. non-quoted blocks) if ($key = !$key) { - preg_match_all('/(R((?:\[-?\d*\])|(?:\d*))?)(C((?:\[-?\d*\])|(?:\d*))?)/i', $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); + preg_match_all(self::R1C1_COORDINATE_REGEX, $value, $cellReferences, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); // Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way // through the formula from left to right. Reversing means that we work right to left.through // the formula