Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6007463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:41:04+00:00 2026-05-23T01:41:04+00:00

Since POSIX regular expressions (ereg) are deprecated since PHP 5.3.0, I’d like to know

  • 0

Since POSIX regular expressions (ereg) are deprecated since PHP 5.3.0, I’d like to know an easy way to convert the old expressions to PCRE (Perl Compatible Regular Expressions) (preg).

Per example, I have this regular expression:

eregi('^hello world');

How can I translate expressions into preg_match compatible expressions?

Note: This post serves as a placeholder for all posts related to conversion from ereg to preg, and as a duplicate options for related questions. Please do not close this question.

Related:

  • How to change PHP’s eregi to preg_match
  • Changing ereg_replace to equivalent preg_replace
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:41:05+00:00Added an answer on May 23, 2026 at 1:41 am

    The biggest change in the syntax is the addition of delimiters.

    ereg('^hello', $str);
    preg_match('/^hello/', $str);
    

    Delimiters can be pretty much anything that is not alpha-numeric, a backslash or a whitespace character. The most used are generally ~, / and #.

    You can also use matching brackets:

    preg_match('[^hello]', $str);
    preg_match('(^hello)', $str);
    preg_match('{^hello}', $str);
    // etc
    

    If your delimiter is found in the regular expression, you have to escape it:

    ereg('^/hello', $str);
    preg_match('/^\/hello/', $str);
    

    You can easily escape all delimiters and reserved characters in a string by using preg_quote:

    $expr = preg_quote('/hello', '/');
    preg_match('/^'.$expr.'/', $str);
    

    Also, PCRE supports modifiers for various things. One of the most used is the case-insensitive modifier i, the alternative to eregi:

    eregi('^hello', 'HELLO');
    preg_match('/^hello/i', 'HELLO');
    

    You can find the complete reference to PCRE syntax in PHP in the manual, as well as a list of differences between POSIX regex and PCRE to help converting the expression.

    However, in your simple example you would not use a regular expression:

    stripos($str, 'hello world') === 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since regular jQuery animations are not fluent on iOS ( .hide() , slideDown() ),
Since now I have only used plugin for editing and the way I use
Since I have no errors I don't know if this is the right place
Is the XSI/System V IPC is outdated since we have POSIX IPC mechanisms available
I need to convert the a time measured in milliseconds since the epoch to
since memcpy should be highly optimized nowadays, does it still make sense to optimize
since today im facing a strange problem. When i start my app in my
Since I am developing an iOS >= 5.0 application, I am trying to change
Since REST is stateless, each request that comes in has no knowledge of the
Since input and raw_input() stop the program from running anymore, I want to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.