/ # identify URLs within a text file
[^="] # do not match URLs in IMG tags like:
# <img src="http://mysite.com/mypic.png">
http|ftp|gopher # make sure we find a resource type
:\/\/ # ...needs to be followed by colon-slash-slash
[^ \n\r]+ # stuff other than space, newline, tab is in URL
(?=[\s\.,]) # assert: followed by whitespace/period/comma
/
可以使用verbose模式编写可读性更强的正则表达式。在此模式下:
以下两种说法相当:
(摘自verbose mode文档)
您可以在regex中使用注释,这使它们更具可读性。以http://gnosis.cx/publish/programming/regular_expressions.html为例:
虽然@Ayman关于
re.VERBOSE
的建议是一个更好的主意,但是如果你只想展示你所展示的内容,那么就做:而Python的相邻字符串文本的自动连接(很像C,btw)将完成其余的工作;-)。在
相关问题 更多 >
编程相关推荐