如何从Python中的字符串中提取占位符子字符串?

时间:2019-06-13 12:06:26

标签: python-3.x string placeholder

我有这个字符串"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']

0 个答案:

没有答案