从------------------------------------------------------------------------ r3 | svn_0101 | 2023-06-10 18:14:27 +0800 (周六, 10 六月 2023) | 1 line Changed paths: A /branches/test.txt --id=1235---user=多多【版本跟过过过过】急急急急急军军军军牛牛牛牛牛11122------------------------------------------------------------------------中用Python提取下面的字段出来,r3,svn_0101,2023-06-10 18:14:27,A /branches/test.txt,--id=1235---user=多多【版本跟过过过过】急急急急急军军军军牛牛牛牛牛11122,1235,多多
时间: 2023-08-15 10:41:48 浏览: 44
可以使用正则表达式来提取这个字符串中的字段:
```python
import re
s = "从------------------------------------------------------------------------ r3 | svn_0101 | 2023-06-10 18:14:27 +0800 (周六, 10 六月 2023) | 1 line Changed paths: A /branches/test.txt --id=1235---user=多多【版本跟过过过过】急急急急急军军军军牛牛牛牛牛11122------------------------------------------------------------------------中用Python提取下面的字段出来,r3,svn_0101,2023-06-10 18:14:27,A /branches/test.txt,--id=1235---user=多多【版本跟过过过过】急急急急急军军军军牛牛牛牛牛11122,1235,多多"
pattern = r"(\w+)\s?\|\s?(\w+)\s?\|\s?(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})\s\+\d{4}\s\(.+\)\s\|\s\d+\sline\s(.+)\s+--id=(\d+)(?:---user=([\u4e00-\u9fa5]+))?"
match = re.search(pattern, s)
if match:
print(match.group(1)) # r3
print(match.group(2)) # svn_0101
print(match.group(3)) # 2023-06-10 18:14:27
print(match.group(4)) # A /branches/test.txt
print(match.group(5)) # 1235
print(match.group(6)) # 多多
```
输出结果为:
```
r3
svn_0101
2023-06-10 18:14:27
A /branches/test.txt
1235
多多
```