我有一个regex PROTO\s*\{(\n*\s*\w+,)+\n*\s*\}
来匹配文本文件,如下所示
PROTO {
product1,
product2,
product3,
product4,
product5,
product6,
}
SAVE_LOG: True
SUMMARY: True
如何使用上面提到的regex将输出转换为
['product1', 'product2', 'product3', 'product4', 'product5', 'product6']
Tags:
如果您能够安装较新的^{} 模块(它支持
\G
修饰符),您可以想出类似(demo on regex101.com)的方法:在
Python
中,这将是:它的优点是只有一个regex(另外编译),因此它可能更快。你知道吗
这将获得所需的阵列:
这不需要regex,您可以通过简单的字符串函数实现所需的功能。你知道吗
相关问题 更多 >
编程相关推荐