Page 1 of 1

reguller expression

Posted: Mon Mar 05, 2007 4:53 am
by itsmani1
from a big html i want i to fetch this:

Code: Select all

<ul class="linklist16">
  <li><a href="art.php?id=3">Camilla to undergo major operation</a></li>
  <li><a href="art.php?id=3741703">'SAS bid to free kidnapped Britons'</a></li>
  <li><a href="art.php?id=3761180">Big rise in 999 ambulance call-outs</a></li>
  <li><a href="art.php?id=3614991">Stephen Hawking to go weightless</a></li>
  <li><a href="art.php?id=3760313">New intervention over email report</a></li>
  <li><a href="art.php?id=3760314">Diana pre-inquest hearing under way</a></li>
  <li><a href="art.php?id=3745484">Zeebrugge victims remembered</a></li>
  <li><a href="art.php?id=3747337">Presidential hopefuls hit town</a></li>
  <li><a href="art.php?id=3691839">Tornadoes in the US kill 20</a></li>
</ul>
This i want to do with preg_match() function
I think my reguller expression can start like:

Code: Select all

^<ul class="linklist16">
but how to close it?
any help?

thank you

Posted: Mon Mar 05, 2007 6:27 am
by Kieran Huggins
<ul class="linklist16">.*?<\/ul>

?

Posted: Mon Mar 05, 2007 7:06 am
by itsmani1
tried this:

Code: Select all

$exp = "<ul class=.*?<\/ul>";
	echo preg_match($exp, $content);
but not working

Posted: Mon Mar 05, 2007 7:46 am
by feyd
The pattern does not have start and end delimiters.

Posted: Mon Mar 05, 2007 7:50 am
by dude81
I'm sure ,this should work

Code: Select all

$pattern='/(<ul(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)+.*<\/ul>/si';
preg_match($pattern,$exp,$x);
print($x);
$x will get the result. The base expression is from a php net site.

Posted: Mon Mar 05, 2007 9:27 am
by Kieran Huggins
itsmani1: start and end delimiters are the / / or # # around most regular expressions

Posted: Tue Mar 06, 2007 12:13 am
by itsmani1
thank you,

I tried this code to catch data between <td width="8" class="page_l">&nbsp;</td> and <td width="15" valign="top" bgcolor="#f78222" class="wPage_r_tiler"> but its not working i don't know what's the problem with it.

Code: Select all

$pattern='/(<td width="8" class="page_l">&nbsp;</td>(.*)+.*<\/<td width="15" valign="top" bgcolor="#f78222" class="wPage_r_tiler">/si';
preg_match($pattern,$data,$x);
print($x);

Posted: Tue Mar 06, 2007 4:53 am
by Kieran Huggins

Code: Select all

(.*)+.*<\/
should be

Code: Select all

(.*?)