使用Python政策表达式 表达式匹配commit id: commit message: author 三个参数<title><p>commit id:27ec7be2e</p><p>author:gao.mengjia</p><p>commit message:1.加 4.0x1b7的子</p></title>
时间: 2023-07-09 10:17:14 浏览: 56
以下是使用Python政策表达式实现的代码示例:
```python
import re
# 匹配 commit id、commit message 和 author 的正则表达式
commit_id_pattern = r'commit id:(\w+)'
commit_message_pattern = r'commit message:(.*)'
author_pattern = r'author:(.*)'
# 匹配 HTML 标签的正则表达式
html_tag_pattern = r'<.*?>'
# 待匹配的字符串
string_to_match = '<title><p>commit id:27ec7be2e</p><p>author:gao.mengjia</p><p>commit message:1.加 4.0x1b7的子</p></title>'
# 匹配 commit id
commit_id_match = re.search(commit_id_pattern, string_to_match)
commit_id = commit_id_match.group(1)
# 匹配 commit message
commit_message_match = re.search(commit_message_pattern, string_to_match)
commit_message = commit_message_match.group(1)
# 去除 HTML 标签
commit_message = re.sub(html_tag_pattern, '', commit_message)
# 匹配 author
author_match = re.search(author_pattern, string_to_match)
author = author_match.group(1)
print('commit id:', commit_id)
print('commit message:', commit_message)
print('author:', author)
```
输出结果为:
```
commit id: 27ec7be2e
commit message: 1.加 4.0x1b7的子
author: gao.mengjia
```