diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java index d7059de03..875c15a35 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/QuantityType.java @@ -70,11 +70,11 @@ public class QuantityType> extends Number public static final QuantityType ZERO = new QuantityType<>(0, AbstractUnit.ONE); public static final QuantityType ONE = new QuantityType<>(1, AbstractUnit.ONE); - // Regular expression to split unit from value. Split on any blank character, even none (\\s*) - // which occurs after a digit (?<=\\d) and before a "unit" character ?=[a-zA-Z°µ\u03BC%'] - // which itself must not be preceded by plus/minus digit (?![\\+\\-]?\\d). + // Regular expression to split unit from value. Split on any blank character, or + // between a digit (?<=\\d) and a non-digit character (?=\\D) + // which must not be preceded by plus/minus digit (?![\\+\\-]?\\d). // The latter would be an exponent from the scalar value. - private static final String UNIT_PATTERN = "(?<=\\d)\\s*(?=[a-zA-Z°µ\u03BC%'](?![\\+\\-]?\\d))"; + private static final String UNIT_PATTERN = "\\s+|(?<=\\d)(?=\\D(?![\\+\\-]?\\d))"; static { UnitInitializer.init(); diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java index e521be9e8..df345d70e 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/library/types/QuantityTypeTest.java @@ -143,6 +143,11 @@ public class QuantityTypeTest { new QuantityType<>("0E-22 m"); new QuantityType<>("10E-3"); new QuantityType<>("10E3"); + new QuantityType<>("1 /s"); + new QuantityType<>("1/s"); + new QuantityType<>("1Ω·m"); + new QuantityType<>("1 Ω·m"); + new QuantityType<>("1.5E2Ω·m"); QuantityType.valueOf("2m"); } @@ -158,6 +163,10 @@ public class QuantityTypeTest { assertEquals(QuantityType.valueOf("1.1e3\u03BCm"), QuantityType.valueOf("1.1E3 µm")); assertEquals(QuantityType.valueOf("1.1e3 \u00B5m"), QuantityType.valueOf("1.1E3 µm")); assertEquals(QuantityType.valueOf("1.1e3\u00B5m"), QuantityType.valueOf("1.1E3 µm")); + assertEquals(QuantityType.valueOf("1.1e3Ω·m"), QuantityType.valueOf("1.1E3 Ω·m")); + assertEquals(QuantityType.valueOf("1.1e3 Ω·m"), QuantityType.valueOf("1.1E3 Ω·m")); + assertEquals(QuantityType.valueOf("1.1e3/s"), QuantityType.valueOf("1.1E3 /s")); + assertEquals(QuantityType.valueOf("1.1e3 /s"), QuantityType.valueOf("1.1E3 /s")); } @ParameterizedTest