I tried to do this:

string pattern = @"^\s+"; Regex regex = new Regex(pattern, RegexOptions.Singleline); 

but when I try to perform

  Match match = regex.Match("list command"); 

returns to me "" .

    1 answer 1

    Most likely, you just confused big and small S

    \s is a whitespace character

    \S is any character except the space character, you need to write this:

     ^\S+ 

    or for loyalty:

     ^\S+\s 
    • Should I write at all? Or if necessary, is it necessary to close the $ ? - nick_n_a
    • @nick_n_a, because you need to take the word that comes from the beginning of the line. - Crantisz
    • @nick_n_a, you only need to get the first word. And the characters ^ and $ are not paired - they can be used separately - mymedia
    • one
      I really got it all mixed up, but in my case ^\S+\s will not work, because I don't need to grab a space along with the word, but ^\S+ seems to work fine. Thank. - 4ezy