Regex

Hey all,

Been reading some regex tutorials lately and figured it’s time to start putting this stuff into practice… Unfortunately that isn’t working so well at the moment haha

I’m trying to match a paragraph in a HTML document, so for example:



<p style = "blah">This is a test paragraph <b>OK</b></p>


Here is my current attempt:



^(<p).*(</p>)$


Any help would be greatly appreciated!

Nick :slight_smile:


	$strPara = '<p style = "blah">This is a test paragraph <b>OK</b></p>';
	printf('<p>&#37;s</p>',preg_replace('/^<p.*?>(.*?)<\\/p>$/','$1',$strPara));

Hey oddz! Thanks for the quick reply!

Run into a problem with that regex when reading the entire html document because it will match from the first opening p tag to the final closing p tag. For example:



<?php

  $strPara = '<p style = "blah">This is a test paragraph <b>OK</b></p><p style = "blah">This is a test paragraph <b>OK2</b></p><p style = "blah">This is a test paragraph <b>OK4</b></p>';
  printf('<p>%s</p>',preg_replace('/^<p.*?>(.*?)<\\/p>$/','$1',$strPara));

?>


Outputs:

This is a test paragraph OK

This is a test paragraph OK2

This is a test paragraph OK4

How can I get around this?

Thanks again,

Nick :slight_smile: