Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:使用正则表达式提取十进制后的值_Python_Regex - Fatal编程技术网

Python:使用正则表达式提取十进制后的值

Python:使用正则表达式提取十进制后的值,python,regex,Python,Regex,我得到一个字符串,它是数字示例44.87或44.8796。我想提取小数点后的所有内容。。我尝试在Python代码中使用正则表达式,但没有成功。我不熟悉Python 3 import re s = "44.123" re.findall(".","44.86") 类似s.split'.[1]的功能应该可以使用如果您想使用正则表达式,请尝试: import re s = "44.123" regex_pattern

我得到一个字符串,它是数字示例44.87或44.8796。我想提取小数点后的所有内容。。我尝试在Python代码中使用正则表达式,但没有成功。我不熟悉Python 3

import re

s = "44.123"
re.findall(".","44.86")

类似s.split'.[1]的功能应该可以使用

如果您想使用正则表达式,请尝试:

import re

s = "44.123"
regex_pattern = "(?<=\.).*"
matched_string = re.findall(regex_pattern, s)

?请展示你尝试过的东西;也许我们可以帮助解释为什么它不起作用。请尝试将“\.\d+$”作为正则表达式模式,而不是“.”。如果字符串包含字母或特殊字符怎么办。。。毕竟它只是一个字符串。这个方法仍然有效。从本质上讲,它是从左到右搜索以确定第一个周期,然后返回后面的所有内容。