Created
December 4, 2009 20:45
-
-
Save markpasc/249347 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) | |
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import re | |
>>> cdnize = re.compile(r'http://www.example.com/(images.*)') | |
>>> text = ("""<p><a href="http://www.example.com/images/full_size_image.jpg">""" | |
... """<img src="http://www.example.com/images/assets_c/thumbnail.jpg">""" | |
... """</a></p>""") | |
>>> print text | |
<p><a href="http://www.example.com/images/full_size_image.jpg"><img src="http://www.example.com/images/assets_c/thumbnail.jpg"></a></p> | |
>>> re.sub(cdnize, r'http://www-example-com.vimg.net/\1', text, count=10) | |
'<p><a href="http://www-example-com.vimg.net/images/full_size_image.jpg"><img src="http://www.example.com/images/assets_c/thumbnail.jpg"></a></p>' | |
>>> text = ("""<p><a href="http://www.example.com/images/full_size_image.jpg">\n""" | |
... """<img src="http://www.example.com/images/assets_c/thumbnail.jpg">\n""" | |
... """</a></p>""") | |
>>> print text | |
<p><a href="http://www.example.com/images/full_size_image.jpg"> | |
<img src="http://www.example.com/images/assets_c/thumbnail.jpg"> | |
</a></p> | |
>>> re.sub(cdnize, r'http://www-example-com.vimg.net/\1', text, count=10) | |
'<p><a href="http://www-example-com.vimg.net/images/full_size_image.jpg">\n<img src="http://www-example-com.vimg.net/images/assets_c/thumbnail.jpg">\n</a></p>' | |
>>> | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment