命名空间 System.Text.RegularExpressions
Regex obj = new Regex("[a-z]{10}"); ///搜索长度为10的a-z的英文字母 , 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);
input :要搜索匹配的字符串
patterm:要匹配的正则表达式模式
options:枚举值的一个按位组合,这些枚举值提供匹配选项
matchTimeout:超时时间
返回结果:找到匹配项为true,未找到匹配项为false
关于参数RegexOptions
它是一个枚举类型,有以下 枚举值
RegexOptions枚举值 | 内联标志 | 简单说明 |
ExplicitCapture | n | 只有定义了命名或编号的组才捕获 |
lgnoreCase | i | 不区分大小写 |
lgnorePatternWhitespace | x | 消除模式中的非转义空白并启用由#标记的注释 |
MultiLine | m | 多行模式,其原理是修改了^和$的含义 |
SingleLine | s | 单行模式,和MultiLine相对应 |
内联标志可以更小力度(一组为单位)的定义匹配选项
@符号:在正则表达式字符串前面加上@字符,不让编译器去解析其中转义字符,而作为正则表达式的语法(元字符)存在。
静态方法
Match Match(string input ,string pattern);
Match Match(string input ,string pattern,RegexOptions options);
Match Match(string input ,string pattern,RegexOptions options,TimeSpan matchTimeout);
搜索指定的正则表达式的第一个匹配项,返回一个包含有关匹配的信息的对象
静态方法
MatchCollection Matches(string input ,string pattern);
MatchCollection Matches(string input ,string pattern,RegexOptions options);
MatchCollection Matches(string input ,string pattern,RegexOptions options,TimeSpan matchTimeout);
搜索指定的正则表达式的所有匹配项,返回所有匹配项
静态方法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);
·关于我们·免责声明·服务条款·RSS订阅·dede168.com技术支持
Copyright © 1998-2015 All rights reserved.