[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 798
  • Last Modified:

PCRE vs. POSIX

I've been reading the "Zend PHP Certification Study Guide," which, several times, recommends the use of the PCRE-based regex functions over the POSIX-based functions, stating that they're faster and more flexible--but not really explaining why or how. I've also noticed that the PHP manual seems to heavily favor the PCRE functions as well. I've always used the PCRE functions, since that was what I was taught to use. In fact, I didn't really realize some of the POSIX methods existed until a little while ago. But my question is this: if the PCRE functions are so much greater in every scenario, why are the POSIX ones even supported, at all? Are there *any* instances when it's better to use POSIX over PCRE? (e.g. ereg() over preg_match()?)

http://www.php.net/manual/en/ref.regex.php
http://www.php.net/manual/en/ref.pcre.php
0
soapergem
Asked:
soapergem
  • 2
1 Solution
 
Richard QuadlingSenior Software DeverloperCommented:
From what I can tell it seems that the PCRE is simply more current in development. A flavour of the month. And as such gets more attention.

Also, the actual syntax for the POSIX based regexp is less flexible ...

From the PHP Manual ...

PHP also supports regular expressions using a Perl-compatible syntax using the PCRE functions. Those functions support non-greedy matching, assertions, conditional subpatterns, and a number of other features not supported by the POSIX-extended regular expression syntax.

0
 
soapergemAuthor Commented:
> A flavour of the month.

Hmm, okay. I wonder if maybe the POSIX came first and then were replaced, or something along those lines. I'll continue using the PCRE functions though, thanks. But by any chance, do you ever use the other ones? (e.g. ereg/eregi/ereg_replace)
0
 
Richard QuadlingSenior Software DeverloperCommented:
Nope!

I've only ever used the PCRE. I used the same underlying library with Delphi and C many years ago when I was working with those languages.

It was not until I got to PHP do I learn about the POSIX variant.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now