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("[email protected]€£#$%^&*()_-+=}{[]|\‘:;?/>.<,~"") == 3
LowercaseCountCheck("") == 0
LowercaseCountCheck("[email protected]€£#$%^&*()_-+=}{[]|\‘:;?/>.<,~"") == 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计数

时间: 2024-08-22 06:05:38

Regex count lowercase letters的相关文章

HDU 3336 Count the string (KMP next数组运用——统计前缀出现次数)

Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6375    Accepted Submission(s): 2947 Problem Description It is well known that AekdyCoin is good at string problems as well as nu

HDU 3336 Count the string (基础KMP)

It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of this string. For example: s: "abab" The prefixes are: "a", "ab&qu

Count the string(hdu3336)

Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7190    Accepted Submission(s): 3318 Problem Description It is well known that AekdyCoin is good at string problems as well as nu

hdu Boring count(BestCode round #11)

Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 360    Accepted Submission(s): 140 Problem Description You are given a string S consisting of lowercase letters, and your task is co

KMP——hdu 3336 count the string

Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10478    Accepted Submission(s): 4893 Problem Description It is well known that AekdyCoin is good at string problems as well as n

hdu 3336 Count the string

Count the stringTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4239    Accepted Submission(s): 1977 Problem Description It is well known that AekdyCoin is good at string problems as well as num

【KMP+DP】Count the string

KMP算法的综合练习 DP很久没写搞了半天才明白.本题结合Next[]的意义以及动态规划考察对KMP算法的掌握. Problem Description It is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s, we can write down all the non-empty prefixes of this str

hdu----(5056)Boring count(贪心)

Boring count Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 228    Accepted Submission(s): 90 Problem Description You are given a string S consisting of lowercase letters, and your task is coun

HDOJ3336 Count the string 【KMP前缀数组】+【动态规划】

Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4212    Accepted Submission(s): 1962 Problem Description It is well known that AekdyCoin is good at string problems as well as n