Jump to content

REG_BADRPT with ereg


pplexr

Recommended Posts

hi,

i am using this regex to extract some content form a html page but this regex dont work and give me Warning: ereg() [function.ereg]: REG_BADRPT

and i tested this code with regexbuddy and it was correct i think maybe its because i should use preg instead of ereg .but i dont know how to do this

here is the regex

$content="html content here";
$pat = '<div id="Body"><p>([\w\W]+)(?:<h3>Related stories</h3>|</div>(?:[\w\W]*)<div id="RelatedStories">)';
$regs = array();
if(ereg($pat,$content,$regs)) {
  $content=$regs[0];
}

thanks,

Link to comment
Share on other sites

Yeah, you need delimiters.  Read the PCRE Syntax section for more info.

 

$content="html content here";
$pat = '/<div id="Body"><p>(.+?)(?:<h3>Related stories<\/h3>|<\/div>.*?<div id="RelatedStories">)/is';
preg_match_all($pat,$content,$matches,PREG_SET_ORDER);
foreach ($matches as $match) echo "$match[1]<br>\n"; // or whatever

 

You only want to capture this part "(.+?)", right?

Link to comment
Share on other sites

Yeah, you need delimiters.  Read the PCRE Syntax section for more info.

 

$content="html content here";
$pat = '/<div id="Body"><p>(.+?)(?:<h3>Related stories<\/h3>|<\/div>.*?<div id="RelatedStories">)/is';
preg_match_all($pat,$content,$matches,PREG_SET_ORDER);
foreach ($matches as $match) echo "$match[1]<br>\n"; // or whatever

 

You only want to capture this part "(.+?)", right?

 

i tried ur code but i got

Warning: preg_replace() [function.preg-replace]: Unknown modifier '(' 

and yes i want to capture "(.+?)"

 

thanks anyway,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.