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

  • Home
  • SEARCH
  • 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 6589317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:09:30+00:00 2026-05-25T17:09:30+00:00

Example: /(?:Foo){0}bar/ I saw something like this in another answer. At first I thought

  • 0

Example:

/(?:Foo){0}bar/

I saw something like this in another answer. At first I thought “what should that be”, but then, “OK could make sense, kind of a negative look behind”, so that Foo is not allowed before bar, but this is not working.

You can see this here on Regexr: It matches only bar but it matches also the bar in Foobar.
When I add an anchor for the start of the row:

/^(?:Foo){0}bar/

it behaves like I expect. It matches only the bar and not the bar in Foobar.

But that’s exactly the same behaviour as if I used only /bar/ or /^bar/.

Is the quantifier {0} only a useless side effect, or is there really a useful behaviour for that?

  • 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-25T17:09:30+00:00Added an answer on May 25, 2026 at 5:09 pm

    There are good uses of {0}. It allows you to define groups that you don’t intend to capture at the moment. This can be useful in some cases:

    • The best one – use of the group in recursive regular expressions (or other weird constructs). Perl, for example, has (?(DEFINE) ) for the same use.
      A quick example – in PHP, this will match barFoo (working example):

      preg_match("/(?:(Foo)){0}bar(?1)/", "barFoo", $matches);
      
    • Adding a failed captured group (named or numbered) to the result matches.

    • Keeping the indices of all groups intact in case the pattern was refactored.

    Less good uses, as Peter suggested are useful in:

    • Generated patterns.
    • Readability – Patterns with certain duplication, where {0} and {1} may lead thinking in the right direction. (OK, not the best point)

    These are all rare cases, and in most patterns it is a mistake.

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

Sidebar

Related Questions

This is just an example, but given the following model: class Foo(models.model): bar =
I saw the example below explained on this site and thought both answers would
I need a some stored procedure that called like: search('foo bar') makes a search
i have a function that receives a function as a parameter. example: function foo(bar:Function):void()
I saw this in some code today. class Foo def self.bar @myvar = 'x'
I need a regular expression which matches: http://example.com/foo http://example.com/foo/ http://example.com/foo/bar but not: http://example.com/foobar Using
If I apply a custom attribute to a class, for example: [Foo] class Bar
An example of the process/output would be: File1: hello world File2: foo bar Resulting
As an example: public class Foo { private Foo() {} } public class Bar
Example: regular_string = %s %s % (foo, bar) result = {} result[somekey] = regular_string,

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.