Posted on 2006-06-06
Last Modified: 2008-01-09
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()?)
Question by:soapergem
    LVL 40

    Accepted Solution

    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.

    LVL 6

    Author Comment

    > 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)
    LVL 40

    Expert Comment


    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.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now