r'\[(.*) -0800\]'
时间: 2023-11-23 14:19:57 浏览: 132
This regular expression matches a string that starts with "[" and ends with " -0800]", and captures everything in between (denoted by the parentheses) using the wildcard character "." and the ".*" quantifier, which means "match zero or more of any character".
In other words, it can extract the timestamp in the format "[Month Day Year Hour:Minute:Second -0800]" from a string.
For example, it would match the timestamp in the following string:
"[Tue, 21 Dec 2021 18:39:42 -0800] User logged in."
and capture "Tue, 21 Dec 2021 18:39:42" as the timestamp.
相关问题
用python 脚本,在 ------------------------------------------------------------------------ r3 | svn_0101 | 2023-06-10 18:14:27 +0800 (周六, 10 六月 2023) | 1 line Changed paths: A /branches/test.txt --id=1235---user=李四【版本跟过过过过】急急急急急军军军军牛牛牛牛牛11122------------------------------------------------------------------------ r6 | svn_0101 | 2023-06-11 17:06:23 +0800 (周日, 11 六月 2023) | 1 line Changed paths: A /branches/4.txt A /branches/6.txt --id=1235---user=张三【版本跟过过过过】急急急急急军军军军牛牛牛牛牛11122 提取时间和姓名,并导出到表格中,表格以时间和姓名作为表头
以下是提取信息并导出到表格中的 Python 脚本:
```python
import re
import csv
# 从文本中提取时间和姓名
def extract_info(text):
pattern = r'^\s*-{72}\n\s*r\d+\s*\|\s*\S+\s*\|\s*(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+\+\d{4})\s+\(.*?\)\s+\|\s+\d+\s+line\s+Changed\s+paths:\s+(.*?)\s+--id=\d+---user=(.*?)【版本跟.*$'
match = re.match(pattern, text, re.DOTALL)
if match:
return match.group(1, 3)
# 读取文本文件
with open('svn_log.txt', 'r', encoding='utf-8') as f:
text = f.read()
# 提取每个记录的时间和姓名
records = []
for match in re.finditer(r'^\s*-{72}\n', text, re.MULTILINE):
record_text = text[match.start():]
next_match = re.search(r'^\s*-{72}\n', record_text[72:], re.MULTILINE)
if next_match:
record_text = record_text[:72+next_match.start()]
info = extract_info(record_text)
if info:
records.append(info)
# 导出到表格
with open('records.csv', 'w', encoding='utf-8', newline='') as f:
writer = csv.writer(f)
writer.writerow(['时间', '姓名'])
writer.writerows(records)
```
将以上代码保存为 `extract_info.py` 文件并与 `svn_log.txt` 文件放在同一目录下,然后在命令行中执行以下命令:
```
python extract_info.py
```
这样就可以生成 `records.csv` 文件,其中包含提取的时间和姓名信息。
File: eswIdeconfig_name.txt Size: 24 Blocks: 8 IO Block: 4096 regular file Device: fd00h/64768d Inode: 12703741 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ user) Gid: ( 1000/ user) Access: 2023-06-09 10:08:40.581334634 +0800 Modify: 2023-06-06 10:19:00.000000000 +0800 Change: 2023-06-09 10:04:11.685526480 +0800 Birth: -
这是使用`stat`命令查看`eswIdeconfig_name.txt`文件的详细信息,其中包括文件大小、占用块数、IO块大小、文件类型、设备信息、inode号、链接数、文件权限、用户ID、组ID、文件访问时间、修改时间、状态改变时间和创建时间(如果有的话)。根据输出结果,该文件的访问时间为2023年6月9日10点08分40秒,修改时间为2023年6月6日10点19分,状态改变时间为2023年6月9日10点04分11秒,但创建时间没有记录。该文件的权限为`-rw-rw-r--`,即可读可写,所属用户和组均为`user`。
阅读全文