Regex count lowercase letters

Description:

Your task is simply to count the total number of lowercase letters in a string.

 

Examples

 

LowercaseCountCheck("abc") == 3
LowercaseCountCheck("abcABC123") == 3
LowercaseCountCheck("abcABC123!@€£#$%^&*()_-+=}{[]|\':;?/>.<,~"") == 3
LowercaseCountCheck("") == 0
LowercaseCountCheck("ABC123!@€£#$%^&*()_-+=}{[]|\':;?/>.<,~"") == 0
LowercaseCountCheck("abcdefghijklmnopqrstuvwxyz") == 26

 

using System.Text.RegularExpressions;

public class Kata
{
  public static int LowercaseCountCheck(string s)
  {
       string pattern = "[a-z]";
            Regex regex = new Regex(pattern);
            var temp = regex.Matches(s);
            return temp.Count;
  }
}

[a-z]是匹配小写字母

用了Matches之后,会把每一个符合条件的提取出来

最后用Count计数

 

posted @ 2016-02-14 04:40  ChuckLu  阅读(354)  评论(0编辑  收藏  举报