python 正则表达式查找标题之间的文本
考虑一下文本:
标题
猫
标题
狗
标题
鸟儿
使用 python 尝试构建一个正则表达式来提取每个 HEADER 部分之间的文本。
我已经尝试过:
results = re.findall(r'HEADER([\s\S]+)(?:HEADER||$))
这最终会捕获捕获组中的所有文本。
假设上面的正则表达式将捕获标题块或标题块和文件末尾之间的所有文本
Consider the text:
HEADER
the cat
HEADER
the dog
HEADER
the bird
Using python attempting to construct a regex to extract the text between each HEADER section.
I have tried:
results = re.findall(r'HEADER([\s\S]+)(?:HEADER||$))
This ends up capturing all the text in the capture group.
Assumption was the above regex would capture all text between to header blocks, or a header block and the end of file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我觉得在这种特定情况下使用 .split("HEADER") 比正则表达式更容易。您是否出于某种原因特别需要正则表达式?
I feel that in that specific case using a .split("HEADER") is easier then a regex. Do you specifically need a regex for some resason?