C#文字列からコンテンツの指定した文字の種類を抽出

中国語、英語、数字を抽出した文字列から、

漢字を30Margin漢字40Horizo​​ntalAlignment

正規表現:

1      ///  <まとめ> 
2つの     /// 文字と数字
 3      ///  </要約> 
。4      パブリック CONST  文字列 lettersAndNumbers = " [A-ZA-Z0-9] + " ;
 5  
。6      ///  <まとめ> 
7つの     /// 漢字
 8。     ///  </要約> 
9。     公的 CONST  文字列 ChineseChars = " [\ u4E00- \ u9FA5] + " ;
 10  
。11      ///  <概要> 
12である     /// 英文字
 13      ///  < /概要>
14      公衆 CONST  文字列 EnglishChars = " [-ZA-Z] + "

正規表現の使用:

1   ChineseChars = " [\ u4E00- \ u9FA5] + " 2  VaRの一致= Regex.Match( "中文字符30Margin中文字符40Horizo​​ntalAlignment"、ChineseChars、RegexOptions.IgnoreCase)。
3  VAR結果= $ " ランキング:{match.Index}、長さ:{match.Length} \ R \ます。nRESULT:{match.Value} "

 

注意:

正規表現は、最初の一致を返します。

あなたはすべての試合に定期的な対応を取得する必要がある場合は、使用することができますRegex.Matches

 

おすすめ

転載: www.cnblogs.com/kybs0/p/11793332.html