<p>Hey so what I want to do is snag the content for the first paragraph. The string <code>$blog_post</code> contains a lot of paragraphs in the following format:</p>

<pre><code>&lt;p&gt;Paragraph 1&lt;/p&gt;&lt;p&gt;Paragraph 2&lt;/p&gt;&lt;p&gt;Paragraph 3&lt;/p&gt;
</code></pre>

<p>The problem I'm running into is that I am writing a regex to grab everything between the first <code>&lt;p&gt;</code> tag and the first closing <code>&lt;/p&gt;</code> tag. However, it is grabbing the first <code>&lt;p&gt;</code> tag and the <strong>last</strong> closing <code>&lt;/p&gt;</code> tag which results in me grabbing everything.</p>

<p>Here is my current code:</p>

<pre><code>if (preg_match("/[\\s]*&lt;p&gt;[\\s]*(?&lt;firstparagraph&gt;[\\s\\S]+)[\\s]*&lt;\\/p&gt;[\\s\\S]*/",$blog_post,$blog_paragraph))
   echo "&lt;p&gt;" . $blog_paragraph["firstparagraph"] . "&lt;/p&gt;";
else
  echo $blog_post;
</code></pre>

It would probably be easier and faster to use
strpos()
to find the position of the first
```
```
<p>
```
```
and first
```
```
</p>
```
```
then use
substr()
to extract the paragraph.
```
```
$paragraph_start = strpos($blog_post, '<p>');
 $paragraph_end = strpos($blog_post, '</p>', $paragraph_start);
 $paragraph = substr($blog_post, $paragraph_start + strlen('<p>'), $paragraph_end - $paragraph_start - strlen('<p>'));
```
```
Edit:
Actually the regex in others' answers will be easier and faster... your big complex regex in the question confused me...