python - 如果我用re.findall 怎么注册才能不分开点

标签 python regex python-2.7

我需要从这个字符串中提取数字:

str="((8,52),(30,52),2,0.5)"

如果我使用:re.findall('\d+',str) 我明白了:

['20', '48', '48', '48', '2', '0', '5']

0.5 有问题

我如何将 0.5 放在一起得到:

['20', '48', '48', '48', '2', '0.5']

最佳答案

re.findall("\d+\.\d+|\d+",str)

正则表达式中的第一个分组将查找小数两边的数字,第二个分组将查找整数。

关于python - 如果我用re.findall 怎么注册才能不分开点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44703436/

相关文章:

Python 正则表达式 : Match ALL consecutive capitalized words

python - 我可以将异常作为参数传递给 python 中的函数吗?

python - 使用 django 模板向后循环

python - 是否可以通过 django 输入表单传递动态 id

regex - .gitignore 用于 emacs 临时文件的正则表达式

PHP 正则表达式删除彼此相邻的句点

python - 用 keras 尝试 Kaggle Titanic .. 得到损失和 valid_loss -0.0000

java 正则表达式 帮助

python-2.7 - 使用 SQLAlchemy 计算具有条件的行数

python - 子应用程序中 'self' 的外键在 Django 项目中的 makemigrations 上抛出错误