Fix RegEx to handle negative values and Ohms without prefix (#530)

* Fix RegEx to include negative values

* Update RegEx to handle Ω without prefix

* Update RegEx to include %

* Handle plus/minus values as range

* Fix copy&paste error

* Change minimum value to negative

* Escape decimal point and add slash to valid unit characters to be able to pick up for example "ppm/°C"

* Skip empty values
This commit is contained in:
frank-f 2024-02-24 22:48:38 +01:00 committed by GitHub
parent 0d6ab793ce
commit e8bc93f67a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View file

@ -106,7 +106,7 @@ class ParameterDTO
*/
public static function splitIntoValueAndUnit(string $value): ?array
{
if (preg_match('/^(?<value>[0-9.]+)\s*(?<unit>[°℃a-zA-Z_]+\s?\w{0,4})$/u', $value, $matches)) {
if (preg_match('/^(?<value>-?[0-9\.]+)\s*(?<unit>[%Ω°℃a-z_\/]+\s?\w{0,4})$/iu', $value, $matches)) {
$value = $matches['value'];
$unit = $matches['unit'];
@ -115,4 +115,4 @@ class ParameterDTO
return null;
}
}
}