Question: I have over 300 items in a list that I need to change the structure of. They are currently structured like this:

```
<li rel="/images/employees/kristi-robison-animated.gif">
    <hgroup>
        <h1>Kristi Robison</h1>
        <h2>Senior Proofreader</h2>
    </hgroup>
    <img src="/images/css/shim.gif" data-static="/images/employees/kristi-robison-static.gif" alt="Kristi Robison">
</li>

```

... and I need to restructure it like this:

```
<li>
    <hgroup>
        <h1>Kristi Robison</h1>
        <h2>Senior Proofreader</h2>
    </hgroup>
    <img src="/images/css/shim.gif" data-static="/images/employees/kristi-robison-static.gif" data-animated="/images/employees/kristi-robison-animated.gif" alt="Kristi Robison">
</li>

```

Because there are so many I don't want to go through and do this manually. Is there a way to do this with a regex and find-and-replace?

Answer: 
Write a script, they're really good at these things! Try piping your html file into this Ruby script for example:

```
while line = gets
  if line[/^(.+?)<li rel="(.+?)">/]
    rel = $2
    line = "#$1<li>"
  elsif line[/^(.+?)<img src="(.+?)" data-static="(.+?)" alt="(.+?)">/]
    line = "#$1<img src=\"#$2\" data-static=\"#$3\" data-animated=\"#{rel}\" alt=\"#$4\">"
  end
  puts line
end

```
totally off topic, but can you even put an hgroup and headings in an li? I'm somewhat new to html5, so maybe that's valid, did you validate?