(しかし、ロジックは言語に関係なく同じです):これは、あなたには、いくつかの代わりに何の制御ではなく何を持っているという利点があり
>>> import re
>>> text = '''
... This is some text
... ________________________
... This some more
... ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
... Truly the last line
... '''
>>> print re.sub(r'[_♥]{2,}', '', text) #this is the core (regexp)
This is some text
This some more
Truly the last line
(たとえば、あなたがいないことを望むかもしれませんそれはThis is still to do...
のようなコメントの一部とすることができるよう.
を代用
EDIT:
あなたの繰り返しは、常にあなたが改行cを追加することができ、「行」であればあなたの式にharacters:
text = '''
This is some text
________________________
This some more
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
Truly the last line
But this is not to be changed: ♥♥♥
'''
>>> print re.sub(r'\n[_♥]{2,}\n', '\n', text)
This is some text
This some more
Truly the last line
But this is not to be changed: ♥♥♥
HTH
出典
2011-10-12 06:10:09
mac
+1、私は 'の代わりに' [^-ZA-Z0-9] '使用します.' –