gpt4 book ai didi

python - 如何在 reStructuredText 中找到标题

转载 作者:太空宇宙 更新时间:2023-11-03 15:17:02 24 4
gpt4 key购买 nike

是否有正则表达式匹配以下标题 reStructuredText - 像文字?困难在于等号的个数必须等于标题的长度。

Some basic text.


=========
One Title
=========

For titles the numbers of sign `=` must be equal to the length of the text title.


=============
Another title
=============

And so on...

最佳答案

搜索 (?:^|\n)(=+)\r?\n(?!=)([^\n\r]+)\r?\n 的匹配项(=+)(?:\r?\n|$)。如果找到匹配项,请检查第一组、第二组和第三组的长度是否相同。如果是这样,标题是第二组的内容。

关于python - 如何在 reStructuredText 中找到标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20312443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com