2011-06-14 41 views

回答

1

您可能需要逃避你逃跑或使用原始字符串。 例如

re.search('(.+) \\1', 'the the') 

re.search(r'(.+) \1', 'the the') 

看到相同的頁面的例子在raw字符串表示部分。

+0

很好的第一個答案。 – 2011-06-15 18:28:40

5

'\1''\x01'。也許你的意思是'(.+) \\1'r'(.+) \1'

0

我會建議使用命名組這樣的:

(?P=name) 

因此,在這種情況下,我會建議使用命名模式和這樣做:

re.search('(?P<first_match>.+) (?P=first_match)', 'the the')