如何算组特定字符串中的字符 [英] How to count sets of specific characters in a string

查看:163
本文介绍了如何算组特定字符串中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我要算组特定字符的字符串。
换句话说,我需要计算所有的字母和数字,而不是其他。
,而我似乎无法找到合适的(正则表达式)语法。
这是我有...

Basically, I want to count sets of specific characters in a string. In other words I need to count all Letters and Numbers, and nothing else. But I cant seem to find the right (regex) syntax. Here's what i have ...

public double AlphaNumericCount(string s)
{
    double count = Regex.Matches(s, "[A-Z].[a-z].[0-9]").Count;
        return count;
}



我一直在四处寻找,但不能似乎发现了什么,让更多不止一个字符集。
同样,我不知道语法的,也许它应该是
[A-Z] / [A-Z] / [0-9]
或什么的。 Anywho,宽容我。 - 使用正则表达式了我的第一天

I've been looking around, but cant seem to find anything that allows more than one set of characters. Again, I'm not sure on the syntax maybe it should be "[A-Z]/[a-z]/[0-9]" or something. Anywho, go easy on me - its my first day using Regex.

感谢

推荐答案

正则表达式小抄

快报正则表达式工具

[AZ]。[AZ] [0-9] 将匹配任何大写字母( [AZ] ),其次为任意字符(),其次是任何小写字母( [AZ] ),其次是任何字符(),后跟任意数量的( [0-9] )。

[A-Z].[a-z].[0-9] will match any capital letter ([A-Z]), followed by any character (.), followed by any lower case letter ([a-z]), followed by any character (.), followed by any number ([0-9]).

要匹配任何字母或数字是什么 [A-ZA-Z0-9]

What you want to match on any letter or number is [A-Za-z0-9].

这篇关于如何算组特定字符串中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆