I don’t know why the code is not working.
But this is how i did this may be helpful for some noob like me
<?php
$name = get_the_content();
preg_match('/\]*)\"]/', $name, $match);
$w3_ids = explode( ",", $match[1] );
$gallery_count=1;
foreach( $w3_ids AS $w3_id ):
$src = wp_get_attachment_image_src($w3_id,'full');
?>
<div class="item <?php if($gallery_count==1)echo "active"; ?>">
<img src="https://wordpress.stackexchange.com/questions/193166/<?php echo $src[0]; ?>" alt="" />
</div>
<?php
$gallery_count++;
endforeach;
?>