mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-21 10:29:31 +00:00
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:
parent
0d6ab793ce
commit
e8bc93f67a
2 changed files with 14 additions and 4 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue