-1

I have this string

copiaElementos = "c'8 d'8 a8"

And when I do Regex.Matches(copiaElementos, "8.").Count() it returns 2

why is that? I don't understand, can anyone please give me a hand?

Thank you, best regards

  • 1
    Dot `.` matches any character, so the two matches are `8` followed by a single space. Please review the basics of regex before posting a question here. – Tim Biegeleisen Mar 05 '20 at 05:35

1 Answers1

0

That is because the . mathes one character. means you are matching an 8 followed by any charactrer, and there are exactly two of those (a space is considered a character too). Because the last one has no characters after it.

if you want to count the 8s in the string you should do Regex.Matches(copiaElementos, "8").Count(). Remember every character, even a space has its own meaning in regex.

Superluminal
  • 947
  • 10
  • 23