我有一个文本块,我想从中删除短语
"Adaptation" means a work based upon the Work, or
cAt
upon the Work and other pre-existing works, such as af
translation,DOG
adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogramf
or performance and includes cinematographic adaptations or any
我想删除cAt
和f
之间DOG
和f
之间或rugrats
和f
之间的任何文本。为了方便起见,我突出显示了文本框中的术语
每个短语(cAt
,DOG
,rugrats
,f
)前后各有一个空格
这是我的密码
clean = `TEXT SHOWN ABOVE`
segment_start = [' cAt ', ' DOG ', ' rugrats ']
segment_end = ' f '
for start in enumerate(segment_start):
clean = re.sub('{}.*{}{1}'.format(start, segment_end), ' ', clean)
我想退出
"Adaptation" means a work based upon the Work, or
translation,cAt
upon the Work and other pre-existing works, such as af
or performance and includes cinematographic adaptations or anyDOG
adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogramf
然后就这样结束了
"Adaptation" means a work based upon the Work, or translation, or performance and includes cinematographic adaptations or any
我的代码出错了。它找到段的开始,然后找到段的最后一次出现f
,并删除其间的所有内容
它是这样做的
"Adaptation" means a work based upon the Work, or
or performance and includes cinematographic adaptations or anycAt
upon the Work and other pre-existing works, such as af
translation,DOG
adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogramf
*
是贪婪的重复:“0或更多,尽可能多”。这使得您的第一个匹配项可以抓取从cAt
到最后一个f
的所有内容,而不为DOG
查询留下任何内容改用
*?
:“0或更多,尽可能少”。这样,regexp将满足于只使用cAt
和第一个f
之间的位,并且DOG
regex也将有它的一天相关问题 更多 >
编程相关推荐