【发布时间】:2020-06-12 10:41:15
【问题描述】:
我有一个字符串:
mystr = "&marker1\nThe String that I want /\n&marker1\nAnother string that I want /\n"
我想要的是标记 start="&maker1" 和 end="/\n" 之间的子字符串列表。因此,预期的结果是:
whatIwant = ["The String that I want", "Another string that I want"]
我在这里阅读了答案:
并尝试过,但没有成功,
>>> import re
>>> mystr = "&marker1\nThe String that I want /\n&marker1\nAnother string that I want /\n"
>>> whatIwant = re.search("&marker1(.*)/\n", mystr)
>>> whatIwant.group(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
我能做些什么来解决这个问题?另外,我有一个很长的字符串
>>> len(myactualstring)
7792818
【问题讨论】:
标签: python python-3.x python-2.7 python-re