Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #4039

Re: regex help

From Kim André Akerø <kimandre@nospambetadome.com>
Newsgroups comp.lang.php
Subject Re: regex help
Date 2011-12-09 14:16 +0100
Organization Betadome Digital Media
Message-ID <op.v574icfkptrp3x@neonk2.intrahouse.local> (permalink)
References <jbs0l0$7nj$1@dont-email.me>

Show all headers | View raw


På Fri, 09 Dec 2011 04:51:56 +0100, skrev Jerry Stuckle  
<jstucklex@attglobal.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)

-- 
Kim André Akerø
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

regex help Jerry Stuckle <jstucklex@attglobal.net> - 2011-12-08 22:51 -0500
  Re: regex help Denis McMahon <denismfmcmahon@gmail.com> - 2011-12-09 11:55 +0000
    Re: regex help Jerry Stuckle <jstucklex@attglobal.net> - 2011-12-09 07:32 -0500
      Re: regex help Jerry Stuckle <jstucklex@attglobal.net> - 2011-12-09 07:51 -0500
  Re: regex help Kim André Akerø <kimandre@nospambetadome.com> - 2011-12-09 14:16 +0100
    Re: regex help Jerry Stuckle <jstucklex@attglobal.net> - 2011-12-09 21:51 -0500
  Re: regex help Curtis Dyer <dyer85@gmail.com> - 2011-12-10 04:25 +0000
    Re: regex help Denis McMahon <denismfmcmahon@gmail.com> - 2011-12-10 10:01 +0000

csiph-web