Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match.
您需要使用一个更简单的regex,比如
:Name\s+\(([^\)]+)\)
。在说明:
:Name
查找Name:
\s+
后跟一个或多个空格\(
后接(
([^\)]+)
捕获()
中的所有内容;如果括号可能为空,请将+
更改为*
\)
以)
结尾findall的文档说明:
所以你的正则表达式的第一部分是不必要的和限制性的。在
见regex101
相关问题 更多 >
编程相关推荐