我想在ObjectUnionOf(
和之后的第一个封闭括号之间进行提取:
<http://www.ifomis.org/bfo/1.1/spanScatteredTemporalRegion> <http://www.ifomis.org/bfo/1.1/spanConnectedTemporalRegion>
这
EquivalentClasses(<http://www.ifomis.org/bfo/1.1/spanTemporalRegion> ObjectUnionOf(<http://www.ifomis.org/bfo/1.1/spanScatteredTemporalRegion> <http://www.ifomis.org/bfo/1.1/spanConnectedTemporalRegion>))
我试过了:
content=content[content.find("ObjectUnionOf(")+1:content.find(")")]
但它不起作用
答案 0 :(得分:1)
使用正则表达式:
import re
s = "EquivalentClasses(<http://www.ifomis.org/bfo/1.1/spanTemporalRegion> ObjectUnionOf(<http://www.ifomis.org/bfo/1.1/spanScatteredTemporalRegion> <http://www.ifomis.org/bfo/1.1/spanConnectedTemporalRegion>))"
m = re.search("ObjectUnionOf\((?P<links>.*?)\)", s)
if m:
print( m.group('links') )
<强>输出:强>
<http://www.ifomis.org/bfo/1.1/spanScatteredTemporalRegion> <http://www.ifomis.org/bfo/1.1/spanConnectedTemporalRegion>
答案 1 :(得分:0)
使用re.findall
:
import re
txt = '''EquivalentClasses(<http://www.ifomis.org/bfo/1.1/spanTemporalRegion> ObjectUnionOf(<http://www.ifomis.org/bfo/1.1/spanScatteredTemporalRegion> <http://www.ifomis.org/bfo/1.1/spanConnectedTemporalRegion>))'''
print('\n'.join(re.findall(r'ObjectUnionOf\((.*)\)\)', txt)))
# <http://www.ifomis.org/bfo/1.1/spanScatteredTemporalRegion>
# <http://www.ifomis.org/bfo/1.1/spanConnectedTemporalRegion>