2012-03-06 153 views
2

爲什麼re.search找不到這個模式?爲什麼這個re.search不起作用

str = "<a href='http://'>\ntest\n'</a>" 
re.search(r"<a[^>]+>.", str, re.MULTILINE) 
+0

你嘗試're.search(R 「] +>」,STR,re.MULTILINE)'.將不匹配換行符? – Nishant 2012-03-06 04:30:08

+0

你不應該使用'str'作爲變量名,因爲它也是內置的 – 2012-03-06 04:30:48

回答

6

,除非你使用re.DOTALL

mystr = "<a href='http://'>\ntest\n'</a>" 
re.search(r"<a[^>]+>.", mystr, re.MULTILINE|re.DOTALL) 
+0

謝謝你,gn​​ibbler。 – Andrey 2012-03-06 04:30:15

+0

非常歡迎 – 2012-03-06 04:31:38