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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:22:01+00:00 2026-06-14T11:22:01+00:00

Basic question about regex mechanics: I have the following expression: [10]*1[10]* . Would this

  • 0

Basic question about regex mechanics:

I have the following expression: [10]*1[10]*.

Would this match 100?

My reasoning:
first option: [10]* matches “100” and then gets to the end of the string => no match.
second option: The [10]* is disregarded and the expression matches.

Am I forgetting something trivial, or will this actually depend on the regex engine?
(I remember something about greedy vs not greedy but I am not sure if that applies to this case)

  • 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-06-14T11:22:02+00:00Added an answer on June 14, 2026 at 11:22 am

    Regex engines do backtracking.

    The engine tries to match 100 with [10]*, but that does not work, because then the 1 has nothing to match. But then the engine throws away the last character of the repetition (only using [10]* for 10) and tries again. Still does not work, because 1 does not match 0. The engine will throw away one character at a time, until the first [10*] is completely dropped. Now the 1 matches and [10]* gladly matches the rest.

    I recommend reading through this tutorial, because it explains very well what is going on under the hood. (For you particular problem, check out the section on Repetition).

    Some more detail:

    This does not depend on whether the repetition is greedy or ungreedy. The regex engine will always backtrack. It will just start from the other end (with 0 occurrences of [10]) if you make it ungreedy like this: [10]*?. In this case that would speed up the process, because the first try would already match, but it would not change the fact, that it always matches.

    In fact, you can manually prevent the engine from backtracking, by making the repetition “possessive”. If you do this, and the repetition is first left, then the engine will not try other possible repetitions. This would be the syntax: [10]*+. Now the engine would match 100 only with that first part. Then matching 1 would fail, but since you made the repetition possessive, it would not go back to try different options to use [10]*. In this case that is useless, of course, but there are use cases where this behavior is desirable. And all of this is also covered in the linked tutorial. 😉

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

Sidebar

Related Questions

I might have pretty basic question about regex. I have the following regex, which
first post, so play nice! I have a fairly basic question about Python dictionaries.
I have BASIC logical question about the following code snippet: 1 uint64_t RMTileKey(RMTile tile)
I have a basic question about parsing expression trees. Is there a difference between
I have a basic question about implementing a Entity code first one to many
I have a basic question about assembly. Why do we bother doing arithmetic operations
This is probably a very basic question about AD FS 2.0 claim rule design
This, I'm sure is a pretty basic question about JavaScript, so apologies in advance.
I'm a Ruby newbie. Have a very basic question about static and instance variables.
I am making a webapp. I have a fairly basic question about javascript performance.

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.