I have a problem with the following;

I'm trying to edit H2 links to add id attributes to them with the following code;

PHP Code:
preg_match_all("/\<h2 id=\"(.*)\">(.*)\<\/h2\>/i",$content,$matches); 
This code works fine with most of my texts, but when I have a text like;

<h2>Title</h2>more text without space

It won't stop at the 2nd boundary and matches the whole string till the next </h2> tag. When I have a \r\n (newline) in place after the 2nd </h2> the script works perfectly. Anyone have an idea on how to fix this? I think I'm missing some kind of limiter. (I've tried \b and \B without success)

Your help is greatly appreciated,