简体   繁体   English

如何拆分字符串章节,使用 python re 包含章节名称?

[英]How do I split a string chapter, include chapter name using python re?

Hi i have a question about re嗨,我有一个关于重新的问题

this is my code这是我的代码

import re
s = '''【chapter list】


【chapter 1】
bob_123

【chapter 2】
check_
....
....
【chapter 3】
AAADDDDCC_AAADDDDCC_AAADDDDCC
AAADDDDCC


【chapter 4】
ADS

'''


s = re.findall(r"【chapter [0-9]+】.*?", s)

#

The result of the code above is below.上面代码的结果如下。

s = ['【chapter 1】', '【chapter 2】', '【chapter 3】', '【chapter 4】']

But I want to split the strings including chapter entries and chapter contents.但我想拆分包括章节条目和章节内容的字符串。

ex) s=['【chapter 1】\n bob_123, 【chapter 2】\n check_\n ....\n...., 【chapter 3】AAADDDDCC_AAADDDDCC_AAADDDDCC \nAAADDDDCC...]

Please help.请帮忙。

I hope this works.我希望这行得通。

r"(【chapter [0-9]+】.*?)+((?:\n.+)+)"

Edit: Added python compliant code.编辑:添加了 python 兼容代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM