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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:46:40+00:00 2026-06-03T18:46:40+00:00

My goal is to find all matches to some pattern in text. Let’s say

  • 0

My goal is to find all matches to some pattern in text.
Let’s say my pattern is:

h.*o

This means I am searching for any text starting with 'h' ending with 'o' and having any number of chars in between (also zero).

My understanding was that method Matches() would deliver multiple matches according description (see MSDN).

const string input = "hello hllo helo";
Regex regex = new Regex("h.*o");

var result = regex.Matches(input);
foreach (Match match in result)
{
    Console.WriteLine(match.Value);
}

My expectation was:

1. "hello"
2. "hllo"
3. "helo"
4. "hello hllo"
5. "hello hllo helo"

To my surprise returned matches contain only one string – the whole input string.

"hello hllo helo"

Questions:

  1. Which one is wrong: my expectation, my regex or usage of class?
  2. How to achieve the result as shown in my example?

Thanks in advance.

  • 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-03T18:46:42+00:00Added an answer on June 3, 2026 at 6:46 pm

    The * is greedy – it will try matching as many characters as it possibly could. You can make it reluctant by following it by question mark, but a better solution is to exclude o from the list if characters the . matches, like this:

    h[^o]*o
    

    Here is a link to very good explanation of greedy vs. reluctant.

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

Sidebar

Related Questions

This is for the Apple platform. My end goal is to do a find
My goal is to find all <?= occurrences with ack. How can I do
My goal here is to find all possible combinations that sums to a given
My goal: Find a DIV, slideUp all of it's child divs, then after all
How can I make this filter work on multiple matches within the same text?
Goal: to find count of all words in a file. file contains 1000+ words
Goal : How we can find the position of subView in a View. I
Though I don't doubt this has been answered I cannot find a great match
I'd like to manipulate a String in Java using Regex. Goal is to find
This is probably a dumb question, but I can't seem to find a good

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.