Question: ```

<!doctype html>
<html>
<head>
  <title>ING Summer Events</title>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <style type="text/css">
            .imagemap {position:relative;width:device-width;}
            img{display:block;}
    </style>
  <script> function callback () { document.querySelector('video').play(); } window.addEventListener("load", callback, false); </script>

</head>

  <body topmargin="0" leftmargin="0" bgcolor=black>

  <img src="./top.jpg" width=100% border="0" />
          <video width="100%" autoplay preload controls poster="./video.jpg">
              <source src="ingsummer.mp4" type="video/mp4">
              <source src="ingsummer.ogg" type="video/ogv">
          </video>
  <img src="./bottom.jpg" width=100% border="0" />

  </body>
</html>

```

This is it, on my Samsung Galaxynote2 it works perfectly...except on Chrome...
What do I supposed to do? I cannot autoplay on Chromes

Answer: 
Using [lxml](http://lxml.de/),

```
import lxml.html as LH
root = LH.fromstring(html_string)
for el in root.iter('img'):
    el.attrib['src'] = 'new src'
print(LH.tostring(root, pretty_print=True))

```

Parsing HTML with regex [is generally a bad idea](http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html).
Using an HTML parser like BeautifulSoup or lxml.html is a better idea.

One attraction of using BeautifulSoup is that it has a familiar Python interface. There are lots of functions for navigation: `find_all`, `find_next`, `find_previous`, `find_parent`, `find_next_siblings`, etc. 

Another point in favor of BeautifulSoup is that sometimes BeautifulSoup can parse broken HTML (by inserting missing closing tags, for example) when `lxml` can not. `lxml` is more strict and simply raises an exception if the HTML is malformed. 

In contrast to the multitude of functions provided by the BeautifulSoup API, `lxml` mainly uses the XPath mini-language for navigation. Navigation using XPath tends to be more succinct than the equivalent using BeautifulSoup. The problem is you have to [learn XPath](http://www.w3schools.com/xpath/xpath_syntax.asp). [lxml is also much much faster than BeautifulSoup.](http://www.crummy.com/2012/01/22/0)

So if you are just starting out, BeautifulSoup may be easier to use instantly, but in the end I believe lxml is more pleasant to work with.
Just throwing this answer in there, if you wanted to use regexes:

```
html = """
<!doctype html>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
</body>
</html>
"""

import re

find = re.compile(r'src="[^"]*"')

print find.sub('src="changed"', html)

```