Forum Moderators: phranque

Message Too Old, No Replies

Need help with a regexp

         

ebloggy

12:59 pm on May 12, 2005 (gmt 0)

10+ Year Member



Hello, I have some text that goes as such:

<a href="http://url">link text</a>
.
.
other html here
.
.
<a href="http://url2">link text2</a>

Basically, is there any way to determine if there is no <img> tag between 'link text' and 'link text2'? I was trying to work out a regular expression but to no avail.

This is how I worked it out using PHP:

preg_match("/<a[^>]+>link text<\/a>(.*)<a[^>]+>link text2<\/a>/Usi", $string, $results);

// After which I use preg_match again to determine if any <img> tag exists in the first backreference i.e. between the two links

if (preg_match("/<img[^>]*>/i", $results[1])
{
echo "Image tag exists.";
}
else
{
echo "Image tag does not exist.";
}

This works but I'm wondering whether instead of two preg_match(es), I can do it in just one.

Thanks in advance!