正则表达式C#
2020-03-09 14:07:21   0  举报             
     
         
 AI智能生成
  正则表达式的知识点,同时附带在C#中正则表达式的使用方法及相关示例。
    作者其他创作
 大纲/内容
  元字符    
     \   
     ^  
     $  
     *  
     +  
     ?  
     {n}  
     {n,}  
     {n,m}  
     ?  
     . 点  
     (pattern)  
     (?:pattern)  
     (?=pattern)  
     (?!pattern)  
     (?<=pattern)  
     (?<!pattern)  
     x|y  
     [xyz]  
     [^xyz]  
     [a-z]  
     [^a-z]  
     \b  
     \B  
     \cx  
     \d  
     \D  
     \f  
     \n  
     \r  
     \s  
     \S  
     \t  
     \v  
     \w  
     \W  
     \xn  
     \num  
     \n  
     \nm  
     \nml  
     \un  
     \<\>  
     \(\)  
     |  
     +  
     ?  
     {i}{i,j}  
     @符号  
     定位元字符    
     \b  
     \B  
     ^  
     $  
     \A  
     \z  
     \Z  
     \G  
     基本语法元字符    
     .  
     \w  
     \W  
     \s  
     \S  
     \d  
     \D  
     示例    
     示例一:校验只允许输入数字  
     示例二:校验只允许输入除大小写字母、0-9的数字、下划线_以外的任何字  
     反义字符    
     \W  
     \S  
     \D  
     \B  
     [ab]  
     [a-c]  
     [^x]  
     [^adwz]  
     示例    
     查找除ahou之外的所有字符  
     重复描述字符    
     {n}  
     {n,}  
     {n,m}  
     ?  
     +  
     *  
     示例    
     校验输入内容是否为合法QQ号(备注:QQ号为5-12位数字)  
     则一匹配字符    
     |  
     示例    
     示例一:查找数字或字母  
     示例二:将人名输出(“zhangqqq;lihshshsh,wanghui.liuhsjsh”)  
     示例三:校验国内电话号码(支持三种写法校验 A. 010-87654321 B. (010)87654321 C. 01087654321 D. 010 87654321)  
     对正则表达式分组    
     ()  
     示例    
     示例一:重复单字符和重复分组字符  
     示例二:校验IP4地址(如:192.168.1.4,为四段,每段最多三位,每段最大数字为255,并且第一位不能为0)  
     位于System.Text.RegularExpressions下的一些静态方法和委托    
     1、静态方法IsMatch(System.Text.RegularExpressions.Regex)    
     bool IsMatch(string input, string pattern);  
     bool IsMatch(string input, string pattern, RegexOptions options);  
     bool IsMatch(string input, string pattern, RegexOptions options, TimeSpan matchTimeout);  
     参数RegexOptions  
     2、静态方法Match(System.Text.RegularExpressions)    
     Match Match(string input, string pattern);  
     Match Match(string input, string pattern, RegexOptions options);  
     Match Match(string input, string pattern, RegexOptions options, TimeSpan matchTimeout);  
     3、静态方法Matches(System.Text.RegularExpressions)    
     MatchCollection Matches(string input, string pattern);  
     MatchCollection Matches(string input, string pattern, RegexOptions options);  
     MatchCollection Matches(string input, string pattern, RegexOptions options, TimeSpan matchTimeout);  
     4、Replace函数(System.Text.RegularExpressions)    
     Replace(string input, string pattern, string replacement);  
     Replace(string input, string pattern, string replacement, RegexOptions options);  
     Replace(string input, string pattern, MatchEvaluator evaluator);  
     Replace(string input, string pattern, MatchEvaluator evalutor, RegexOptions options);  
     5、静态方法Split拆分文本    
     string[] Split(string input, string pattern);  
     string[] Split(string input, string pattern, RegexOptions options);  
     string[] Split(string input, string pattern, RegexOptions options, TimeSpan matchTimeout);  
    
 
 
 
 
  0 条评论
 下一页
  
   
   
   
   
  
  
  
  
  
  
  
  
  
  
 