Skip to main content
1 de 5
Lacobus
  • 13,9mil
  • 13
  • 34
import re

def findDimensions(text):
    return tuple([ float(n) for n in re.sub('[^0-9,.]', ' ', text ).replace(',', '.').split()])

Testando:

import re

def findDimensions(text):
    return tuple([ float(n) for n in re.sub('[^0-9,.]', ' ', text ).replace(',', '.').split()])

print(findDimensions("14,5 x 55 x 22,0"))
print(findDimensions("14,5 x 55cm x 22"))
print(findDimensions("14,5cm x 55 x 22cm"))
print(findDimensions("14,5cmx55x22cm"))
print(findDimensions("14,5 cmx55 cmx22 cm"))
print(findDimensions("14,5 cm x 55.0 x 22.3 cm"))

Saída:

(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)
(14.5, 55.0, 22.0)

Veja a expressão regular funcionano no regex101.com.

Veja o código de teste rodando no Ideone.com

Lacobus
  • 13,9mil
  • 13
  • 34