Re: regex help [message #176249 is a reply to message #176241] |
Sat, 10 December 2011 02:51 |
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
==================
..
|
|
|