python-3.x - 如何从 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']
解决方案
推荐阅读
- java - 如何在 Java 中使用泛型来更轻松地使用 JPA 存储库?
- javascript - 如何制作一个点击下拉的下拉列表?
- list - Xamarin.Android 如何从列表项中分离单词
- php - 获取 WooCommerce Ajax 上的产品 ID、名称和数量添加到购物车以显示通知
- google-maps - 在自定义谷歌地图中添加请求选项,用户可以请求管理员查看其他用户的电话号码
- python - 无法使用 Pandas 解析 JSON 文件
- html - Angular 8:动态添加 Div
- r - ggplot自定义x轴(月)被压缩/不使用整个范围
- python - 无法在 PyCharm 中导入模块,即使它已安装并且正在使用 shell 导入
- c# - ResolveAssemblyReference 任务在目标框架 4.7.2 的 VS 2017 上意外失败