1
所以我有這個序列,我試圖使用正則表達式的搜索功能來查找發生查詢之前的區域和之後的區域。查詢之前和之後的正則表達式查找
這是我
sequence = 'abcdefghijklmnopqrstuvwxyz'
query = 'jklmnop'
這就是我想要的與
before = 'abcdefghi'
after = 'qrstuvwxyz'
我想它的前一個結束了,它不工作。我認爲這將其分成3組
sequence = 'abcdefghijklmnopqrstuvwxyz'
query = 'jklmnop'
print re.search('\w+(query)\w+',sequence).group(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
感謝那是一個很好的解釋但到底是什麼格式做的{}? –
@ draconisthe0ry'{}'是一個佔位符,用於指定傳遞給'format()'的參數值將被存儲(替換)到字符串中的位置。 看一些例子:http://docs.python.org/2/library/string.html#format-examples –