Get images from the post

The Image added by Add Media is included in the Content.So I have splitted the image from the content.Below is the working code for my Question.

<?php $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); ?>

<div class ="single-post-flex-slider">
    <ul class="slides">
        <?php for($i =0;$i<$output;$i++){ ?>
        <li> <img src="https://wordpress.stackexchange.com/questions/174038/<?php echo $matches[1][$i]; ?>" width="500px" height="300px" /></li>
        <?php } ?>
    </ul>
</div>