【发布时间】:2019-12-04 18:17:50
【问题描述】:
我有一个字符串,它围绕特定的单词或子字符串定义了标签。例如:
text = 'Bring me to <xxx>ibis and the</xxx> in <ccc>NW</ccc> and the <sss>Jan</sss>
<hhh>10</hhh>'
如何获取字符串<xxx>ibis and the</xxx>、<ccc>NW</ccc>、<sss>Jan</sss> 和<hhh>10</hhh>。这些标签可以是任何东西,但覆盖一个词或几个词的标签将是相似的。此外,如果缺少开始或结束标记,我不希望返回该字符串。例如:
text = 'Bring me to <xxx>ibis and the in NW</ccc> and the <sss>Jan</sss>
<hhh>10</hhh>'
在这种情况下,只需要返回<sss>Jan</sss> 和<hhh>10</hhh>。
【问题讨论】:
-
为什么标记为nsregularexpression?你是在 iOS 上运行 Python 还是什么?
-
@Mast 已更正!
标签: regex python-3.x string substring