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 7597901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:16:22+00:00 2026-05-30T22:16:22+00:00

This is bugging me: Why preg_match(‘/pattern/’, $haystack) instead of preg_match(‘pattern’, $haystack) ? Everything I’ve

  • 0

This is bugging me:

Why preg_match('/pattern/', $haystack) instead of preg_match('pattern', $haystack)? Everything I’ve seen just states as a fact that they’re necessary, and mentions that you can use alternate delimiters.

But, it’s a function that defines its own interface outside of the string. It has a flags argument. Adding intra-string syntax seems capricious.

Is it something inherited from pcre that the authors were just not interested in working around? Yet another perverse fact of PHP? Or is there a justification?

  • 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-30T22:16:24+00:00Added an answer on May 30, 2026 at 10:16 pm

    The delimiters are for compatibility with Perl. Perl regular expressions use the delimiters, and rely on the end delimiter to signify the start of modifier flags, like i for case insensitivity, for example.

    // Match alpha-numeric, case insensitive, multiline
    preg_match('/^[a-z0-9]+$/im', $input);
    

    The optional flags argument to preg_match() does not implement the regular expression flags like i that follow the second delimiter. They serve a different function, and indeed PREG_OFFSET_CAPTURE is the only flag available there. This is not to say the regex flags could not have been implemented as another function parameter. They certainly could have, but Perl-compatibility is the goal here.

    PHP is not the only language that borrows directly from Perl to implement regular expressions. JavaScript does to some degree, and Ruby even implements Perl’s =~ operator for regular expression matches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, this is bugging me, and I just can't figure out what is wrong...
This is a question that's been bugging me for some time now: In photoshop/GIMP,
This is something that's been bugging me for many years: why most online services
This is a question that has been bugging me for a while. I started
This has been bugging me for years, but I've just been ignoring it, like
I have an issue that's been bugging me this morning. I'm building an ASP.NET
This has been bugging me for a while. I have this ircbot that I
This has been bugging me for a while and I'm hoping that one of
This has been bugging me for more than two days now, so i thought
This one has been bugging me for a while now. Is there a way

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.