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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:37:47+00:00 2026-05-13T06:37:47+00:00

(The background for this question is that I thought it would be fun to

  • 0

(The background for this question is that I thought it would be fun to write something that parses wiki creole markup. Anyway the problem that I think I have a solution to is differentiating between // in a url and as opening/closing syntax for italic text)

My question is slightly compound so I’ve tried to break it up under the headings

If there is a substring(S1) that can contain any one of a series of substrings separated by | does the regular expression interpreter simply match the first substring within ‘S1’ then move onto the regular expression after ‘S1’? Or can will it in some instances try find the best/greediest match?

Here is an example to try and make my question more clear:
String to search within: String
Regex: /(?:(Str|Strin).*)/ (the ‘S1’ in my question refers to the non-capturing substring

I think that the matches from the above should be:
$0 will be String
$1 will be Str and not Strin

Will this always happen or are the instances (e.g maybe ‘S1’ being match greedily using *) where the another matching substring will be used i.e. Strin in my example.

If the above is correct than can I/should I rely on this behaviour?

Real world example

/^\/\/(\b((https?|ftp):\/\/|mailto:)([^\s~]*?(?:~(.|$))?)+?(?=\/\/|\s|$)|~(.|$)|[^/]|\/([^/]|$))*\/\//

Should correctly match:

//Some text including a http//:url//

With $1 == Some text including a http//:url

Note: I’ve tried to make this relatively language agnostic but I will be using php

  • 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-13T06:37:47+00:00Added an answer on May 13, 2026 at 6:37 am

    PHP uses the PCRE regex engine. By default, and the way PHP uses it, the PCRE engine runs in longest-leftmost mode. This mode returns the first match, evaluating the regex from left to right. So yes, you can rely on the order that PHP interprets a regex.

    The other mode, provided by the pcre_dfa_exec() function, evaluates all possible matches and returns the longest possible match.

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

Sidebar

Related Questions

Background This question is in two parts. I have a one-way WCF operation hosted
Background: This question relates to versions of Delphi below 2009 (ie without Unicode support
This is my first question so please be patient :) Background: I'm implementing an
I have marked this question as community wiki, so no rep points are thrown
Background This question relates to the new Cirrus infrastructure for Aspect Oriented Programming in
Background this post explains how one can consume extension methods in Powershell http://community.bartdesmet.net/blogs/bart/archive/2007/09/06/extension-methods-in-windows-powershell.aspx Compare
First off, there's a bit of background to this issue available on my blog:
Background In Visual Studio 2008 Create a new Windows Forms Application, this will create
This is pretty simple, I come from a swing/awt background. I'm just wondering what
in a CSS like this : ... #big-menu { background: #fff url(../images/big-menu.jpg) no-repeat; }

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.