首页 > 解决方案 > 如何从 Python 中的字符串中提取占位符子字符串?

问题描述

我有这个字符串"this ${is} a sample ${text}" 我想要一个包含 ${} 的所有子字符串的列表

我试过了,它奏效了

re.findall("{(.*?)}", "this ${is} a sample ${text}")
['is', 'text']

However, I would like to narrow down the search by using the $ symbol too. 
The following command return []
re.findall("${(.*?)}", "this ${is} a sample ${text}")


re.findall("${(.*?)}", "this ${is} a sample ${text}")

The expected output should be ['is', 'text']

标签: python-3.xstringplaceholder

解决方案


推荐阅读