text = 班级 1 中:有 [张三] ,有 [李四] ,还有 [王五] 等同学。
re.search(r' [.+] ', text) 把整个字符全匹配上了:
[张三] ,有 [李四] ,还有 [王五]
怎么单独匹配:
[张三]
[李四]
[王五]
1
h503mc 2020-04-05 16:42:10 +08:00 via iPhone
转义掉中括号
|
2
X-Force 2020-04-05 16:43:15 +08:00
\[.+\]
|
3
h503mc 2020-04-05 16:43:31 +08:00 via iPhone
\[.+\]
|
4
crab 2020-04-05 16:44:50 +08:00 1
\[.*?]
|