none
About empty characters? RRS feed

  • Question

  • Hi all;)

     var s = "1,2,3,4,5,6,123,ab,.,abcde;";
                var r = Regex.Matches(s, @"\w+|\.");
    
                foreach (var z in r)
                {
                    Console.WriteLine(z);
                }

    This will output:

    However if I change this:

    \w*|\.

    This will output:

    Can anyone explain why there are so many "empty characters"??????

    Wednesday, March 13, 2013 7:48 AM

Answers

  • The Regex Quick language guid says the following :

    +  : Matches the previous element one or more times.

    * : Matches the previous element zero or more times.

    The * is putting a white character for every non match.  So you have nine commas and one semicolon.


    jdweng

    • Marked as answer by ToughMan Wednesday, March 13, 2013 1:10 PM
    Wednesday, March 13, 2013 9:20 AM
  • The difference betwee + and * is + looks for >=1 matches and * looks for >=0 matches.

    jdweng


    • Edited by Joel Engineer Wednesday, March 13, 2013 9:53 AM
    • Marked as answer by ToughMan Wednesday, March 13, 2013 1:10 PM
    Wednesday, March 13, 2013 9:52 AM

All replies

  • The Regex Quick language guid says the following :

    +  : Matches the previous element one or more times.

    * : Matches the previous element zero or more times.

    The * is putting a white character for every non match.  So you have nine commas and one semicolon.


    jdweng

    • Marked as answer by ToughMan Wednesday, March 13, 2013 1:10 PM
    Wednesday, March 13, 2013 9:20 AM
  • Hi Joe,

    The * is putting a white character for every non match

    What does this mean?

    And "\w+" means that I'll find 0 or more than 0's characters such as a-z,A-Z,0~9
    • Edited by ToughMan Wednesday, March 13, 2013 9:41 AM
    Wednesday, March 13, 2013 9:40 AM
  • The difference betwee + and * is + looks for >=1 matches and * looks for >=0 matches.

    jdweng


    • Edited by Joel Engineer Wednesday, March 13, 2013 9:53 AM
    • Marked as answer by ToughMan Wednesday, March 13, 2013 1:10 PM
    Wednesday, March 13, 2013 9:52 AM