No subject


Mon Feb 7 10:29:41 EST 2005


                Table of Contents
                preg_match - Perform a regular expression match
                preg_match_all - Perform a global regular expression match
                preg_replace - Perform a regular expression search and replace
                preg_replace_callback - Perform a regular expression search 
and replace using a callback
                preg_split - Split string by a regular expression
                preg_quote - Quote regular expression characters
                preg_grep - Return array entries that match the pattern 


On 22-Jul-2001 Michael P. Soulier wrote:
>     Hey people. 
> 
>     I'm having a problem matching the first paragraph of a block of text,
> where the paragraph is defined in HTML. 
> 
> <p>This is the first
> paragraph.</p>
> <p>This is the second</p>
> 
>     Now, I just want the first, so I tried this:
> 
>     if (eregi("(<p>.+[^>]</p>)", $buffer, $regs)) {

>         $firstpara = $regs[1];
>     }
> 
>     The negation should prevent matching of any nested HTML tags. Not quite
> what I want since I only want to prevent nested <p> tags, but I can't even
> get
> this to work. 

The negation doesn't work like that.  What you have is match <p>, any character
1 or more times, then any non >, then </p>.

Instead try :

if (eregi("(<p>[^>]+</p>)", $buffer, $regs)) {

which is match <p>, any character that isn't a > 1 or more times, than </p>.   

>     I'd use a lookahead assertion in Perl, but this is PHP. I could use a
> hand. 
> 
>     Thanks,
> 
>     Mike
> 
> -- 
> Michael P. Soulier <msoulier at storm.ca> 
> "With sufficient thrust, pigs fly just fine. However, this is not necessarily
> a
> good idea. It is hard to be sure where they are going to land, and it could
> be
> dangerous sitting under them as they fly overhead." -- RFC 1925






---

                                     Dynamic Hosting
                                   HTTP://www.L8R.net/             
                      "We Provide Static Hostnames for Dynamic IP's"



More information about the OCLUG mailing list