FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » regex help
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: regex help [message #176249 is a reply to message #176241] Sat, 10 December 2011 02:51 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 12/9/2011 8:16 AM, Kim André Akerø wrote:
> På Fri, 09 Dec 2011 04:51:56 +0100, skrev Jerry Stuckle
> <jstucklex(at)attglobal(dot)net>:
>
>> OK, guys, I'll be the first to admit my regex knowledge is more than
>> limited. And I've never used ereg().
>>
>> So, I need to convert the following ereg() call in some code I'm
>> modifying to a preg() call. Can someone please tell me what the ereg()
>> does and the equivalent preg()?
>>
>> if (ereg("(error</b>:)(.+)(<br)", $buffer, $regs))
>
> ereg() will return the length of the first matched string, if any, or
> FALSE if nothing was found. The "if" surrounding it basically is
> triggered if the return value is non-false.
> On the other hand,preg_match() will return the number of matches (0 or
> 1, since it stops after the first match).
>
> Even though they're pretty close, preg_* follows Perl-based regexes, and
> as you pointed out earlier, ereg* uses POSIX regexes. Then again, the
> regex in your code line above is simple enough to be converted almost
> verbatim to preg_* functions, with the addition of a separator and
> escaping said separator inside the regex (the forward slash being the
> most commonly used):
>
> if (preg_match("/(error<\/b>\:)(.+)(<br)/", $buffer, $regs) == 1)
>

Thanks, Kim. I do appreciate the help.

It isn't the separators I'm worried about - I've made that mistake
enough times already :). But I have just enough PCRE knowledge to be
dangerous; I can't say that for POSIX regexes.

Thanks again. Looks like it's working just fine, at least for now.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================

..
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: <beg> ADODB PHP Extension Help </beg>
Next Topic: Edit a record?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 12 22:04:19 GMT 2024

Total time taken to generate the page: 0.14394 seconds