Regex count lowercase letters
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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计数
以上是关于Regex count lowercase letters的主要内容,如果未能解决你的问题,请参考以下文章