<p>I'm not much of a coder, but I need to write a simple <em>preg_replace</em> statement in PHP that will help me with a WordPress plugin.  Basically, I need some code that will search for a string, pull out the video ID, and return the embed code with the video id inserted into it.  </p>

<p>In other words, I'm searching for this:  </p>

<pre><code>[youtube=http://www.youtube.com/watch?v=VIDEO_ID_HERE&amp;hl=en&amp;fs=1]
</code></pre>

<p>And want to replace it with this (keeping the video id the same):  </p>

<pre><code>param name="movie" value="http://www.youtube.com/v/VIDEO_ID_HERE&amp;hl=en&amp;fs=1&amp;rel=0
</code></pre>

<p>If possible, I'd be forever grateful if you could explain how you've used the various slashes, carets, and Kleene stars in the search pattern, i.e. translate it from grep to English so I can learn. :-)</p>

<p>Thanks!<br>
Mike</p>

```
```
$str = preg_replace('/\[youtube=.*?v=([a-z0-9_-]+?)&.*?\]/i', 'param name="movie" value="http://www.youtube.com/v/$1&hl=en&fs=1&rel=0', $str);

         /     - Start of RE
         \[    - A literal [  ([ is a special character so it needs escaping)
         youtube= - Make sure we've got the right tag
         .*?   - Any old rubbish, but don't be greedy; stop when we reach...
         v=    - ...this text
         ([a-z0-9_-]+?) - Take some more text (just z-a 0-9 _ and -), and don't be greedy.  Capture it using ().  This will get put in $1
         &.*?\] - the junk up to the ending ]
         /i - end the RE and make it case-insensitive for the hell of it
```
```