Aug 11 2008

Finding tag through regex

Published by Gaurav Mishra at 1:39 am under programming

I am saving this for my reference , A post with all commonly used regex, first one to go is finding <img> tag through php using regex.

$pattern = ‘/<img[^>]+src[\\s=\'"]‘;
$pattern .= ‘+([^"\'>\\s]+)/is’;

if(preg_match($pattern,$subject,$match))
{
echo $match[0];
}

2 Responses to “Finding tag through regex”

  1. [...] >> regex C# Regex MatchCollection Meets Linq First saved by enlightened007 | 3 days ago Finding tag through regex First saved by NewestNuma | 3 days ago regular expressions (aka regEx) tutorial #1 First saved [...]

  2. heidzir MALAYSIA Windows XP Mozilla Firefox 3.0 on 05 Nov 2008 at 9:27 am

    hi,

    the code did not close the img tags properly

    example:

Trackback URI | Comments RSS

Leave a Reply

FireStats icon Powered by FireStats