使用以下正则表达式的下列模式用以提取文本中包含的数字:
pattern = r'[^+\-\d]*([+-]?\d+([.,]\d+)?).*'
text = '123`
result = re.match(pattern, text)
print(result[1]) # => 123
text = '+123`
result = re.match(pattern, text)
print(result[1]) # => +123
text = '-123`
result = re.match(pattern, text)
print(result[1]) # => -123
text = '123.456`
result = re.match(pattern, text)
print(result[1]) # => 123.456
text = '+123.456`
result = re.match(pattern, text)
print(result[1]) # => +123.456
text = '-123.456`
result = re.match(pattern, text)
print(result[1]) # => -123.456
text = '今天气温-10.5度`
result = re.match(pattern, text)
print(result[1]) # => -10.5
text = '今天的气温是-10,5度`
result = re.match(pattern, text)
print(result[1]) # => -10,5