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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:06:20+00:00 2026-05-29T15:06:20+00:00

While answering this question C# Regex Replace and * the point was raised as

  • 0

While answering this question C# Regex Replace and * the point was raised as to why the problem exists. When playing I produced the following code:

    string s = Regex.Replace(".A.", "\w*", "B");
    Console.Write(s);

This has the output: B.BB.B

I get that the 0 length string is match before and after the . character, but why is A replaced by 2 Bs.

I could understand B.BBB.B as replacing zero-length strings either side of A or B.B.B
But the actual result confuses me – any help appreciated.

Or as AakashM has put it:

Why is Regex.Matches("A", "\w*").Count equal to 2, not 1 or 3 ?

  • 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-29T15:06:21+00:00Added an answer on May 29, 2026 at 3:06 pm

    because \w* is a greedy regex and it tries to find biggest sequence. So it matches "nothing" before dot, then "nothing"A between two dots then "nothing" before second dot and finally "nothing" after the second dot.

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

Sidebar

Related Questions

While answering this question I noticed that I got the following dialog while atempting
After answering this question I put together the following C# code just for fun:
So, I was playing around with Python while answering this question , and I
While answering this question regarding safe escaping of filename with spaces (and potentially other
While answering this question I came across an interesting difference in the overload resolution
While answering another question I bumped into this interesting situation Where WCF is happy
While answering this question I noticed that I have never come across any property
While answering this question DOM parser: remove certain attributes only I noticed that some
Kicking around some small structures while answering this post , I came across the
Before answering this question, understand that I am not asking how to create my

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.