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 Rails is not multithreaded (yet), it seems like a threaded web framework would
Since I am not getting anywhere with my previous question , I would like
Since there doesn't seem to be a way for a user to take a
Since Xcode 4, using BWToolkit isn't really easy. In fact, it's not even possible
Since some time ago I have been programming in php with oracle, and I've
Since I started studying object-oriented programming, I frequently read articles/blogs saying functions are better,
Since CS3 doesn't have a web service component, as previous versions had, is there
Since both a Table Scan and a Clustered Index Scan essentially scan all records
Since Graduating from a very small school in 2006 with a badly shaped &
Since the WMI class Win32_OperatingSystem only includes OSArchitecture in Windows Vista, I quickly wrote

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.